Skip to content

fix(filesystem): do not attempt to lock directories on Windows - #10487

Merged
nilsding merged 1 commit into
nextcloud:masterfrom
andreasbohl:fix/directory-lock-check
Jul 31, 2026
Merged

fix(filesystem): do not attempt to lock directories on Windows#10487
nilsding merged 1 commit into
nextcloud:masterfrom
andreasbohl:fix/directory-lock-check

Conversation

@andreasbohl

@andreasbohl andreasbohl commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Resolves

Closes #10444 - fixes the log flooding reported there.

Summary

On Windows, isFileLocked() is called for every entry discovery walks over, directories included. LockFile() locks a byte range within a file and is not supported for directory handles, where it always fails with ERROR_INVALID_PARAMETER. That call is reached at all because FILE_FLAG_BACKUP_SEMANTICS lets CreateFileW() open directories.

This returns the opened handle for directories instead of attempting the lock. CreateFileW() still runs, so a directory another process holds with deny-sharing is still reported as locked, only the attempt that cannot succeed is gone.

Measured on a synced folder with ~80,000 directories, same build and configuration, one full discovery run each: ~80,000 warnings without the change, none with it. The added test asserts both halves and fails without the fix.

I could not reproduce the crash from the issue itself, isFileLocked() returns false after logging. But we did hit on our clients the log flooding and the same errors.

Checklist

  • Sign-off message is added to all commits.
  • The commit history is clean with no merge commits.
  • Uploaded screenshots from before and after for UI changes.
  • Test(s) added to branch, with before/after results included in PR description, for performance improvements where applicable.
  • Documentation has been updated or is not required.
  • Backports requested where applicable (critical bugfixes). -> requesting stable-34
  • Labels added where applicable (bug/enhancement). -> bug, os: Windows
  • Milestone added for target version.

AI (if applicable)

@camilasan

Copy link
Copy Markdown
Member

/backport to stable-34.0

@camilasan

Copy link
Copy Markdown
Member

thanks @andreasbohl 馃檶馃徎

LockFile() locks a byte range within a file and is not supported for
directory handles, where it always fails with ERROR_INVALID_PARAMETER.
FILE_FLAG_BACKUP_SEMANTICS lets CreateFileW() open directories, so
isFileLocked() reached that failing call for every directory and logged a
warning for each one. Discovery checks every entry, directories included,
so a sync run logged one bogus warning per directory. On large folder trees
those warnings dominate the log volume, and the resulting log rotation
discards the records needed to diagnose actual problems.

Return the opened handle for directories instead of attempting the lock.
CreateFileW() still runs, so a directory held with deny-sharing is still
reported as locked; only the attempt that cannot succeed is gone.

Measured on a synced folder with 82464 directories, same build and
configuration: a full discovery run logged 83189 of these warnings without
this change and none with it. The added test covers both halves and fails
without the fix. Test suite green on Windows (70 tests).

For nextcloud#10444

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Andreas Bohl <[email protected]>
@nilsding
nilsding force-pushed the fix/directory-lock-check branch from 08eb545 to f747ff6 Compare July 31, 2026 07:24
@nilsding
nilsding enabled auto-merge July 31, 2026 07:25
@github-actions

Copy link
Copy Markdown
Contributor

Artifact containing the AppImage: nextcloud-appimage-pr-10487.zip

Digest: sha256:1e929b5361e6800bfb39d75e110fcf28e4dd0009af9fd32de2069f6a01f9b051

To test this change/fix you can download the above artifact file, unzip it, and run it.

Please make sure to quit your existing Nextcloud app and backup your data.

@nilsding
nilsding merged commit e5272e2 into nextcloud:master Jul 31, 2026
20 of 21 checks passed
@nilsding

Copy link
Copy Markdown
Member

/backport to stable-33.0 please

@nilsding

Copy link
Copy Markdown
Member

/backport to stable-4.0 please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [v34 RC5] Client crashes during discovery with WindowsError 57 (ERROR_INVALID_PARAMETER) in OCC::FileSystem::isFileLocked

4 participants