Auto-lock: etag change on LOCK/UNLOCK makes the locking client re-download the open file (Access denied, conflict copies)
Bug description
With files_lock enabled, the desktop client auto-locks a file when it detects a lock file next to it (AutoCAD .dwl/.dwl2, or ~$*). Every LOCK and UNLOCK changes the file's etag on the server (files_lock LockService::propagateEtag sets 'etag' => uniqid()), while content, size, mtime and checksum stay the same.
The client that created the lock then treats this etag change as a remote modification of the file that the CAD application still has open:
- it tries to download the file over the open copy:
Renaming temp file to final failed: "WindowsError: 5: Accesso negato."/CreateFileW failed ... WindowsError: 20: ... il file è utilizzato da un altro processo; - if the user saved locally in the meantime, it creates a conflict copy, although nobody else changed the file.
Users experience it as "the file I opened is locked and I can't save it".
Steps to reproduce
- Server with
files_lockenabled, Windows client 35.0.3 with VFS (wincfapi). - Open a
.dwgin a synced folder with AutoCAD (or an AutoCAD-based tool). AutoCAD creates<name>.dwl/.dwl2, and the client auto-locks the.dwg(LockOwnerType::TokenLock). - Edit and save the drawing, then close it. The client uploads, then unlocks.
- The next discovery finds a different remote etag (13 hex chars =
uniqid) with the same mtime and size. The result is a conflict, or a download attempt over the open file.
Log excerpt (paths shortened)
11:02:27.547 lockfilejobs.cpp:53 start with path: ".../00/Q.LUCE.dwg" lock state: LockedItem lock owner type: TokenLock
11:02:27.781 lockfilejobs.cpp:109 success ".../00/Q.LUCE.dwg" LockedItem TokenLock
11:20:00.542 lockfilejobs.cpp:53 start with path: ".../00/Q.LUCE.dwg" lock state: UnlockedItem lock owner type: TokenLock
11:20:00.791 lockfilejobs.cpp:109 success ".../00/Q.LUCE.dwg" UnlockedItem TokenLock
11:20:22.557 discovery Processing ".../00/Q.LUCE.dwg" | (db/local/remote) | mtime: 1794824385/1794824397/1794824385 | size: 607221/617614/607221 | etag: "6afad8720a072"//<new uniqid>
11:20:22.917 owncloudpropagator.cpp:1017 Created conflict file ".../00/Q.LUCE (conflicted copy ...).dwg"
db and remote have the same mtime and size: only the etag changed, because of the client's own UNLOCK. Local was modified, so the expected action is an upload, not a conflict.
Another file, a few seconds after its lock/unlock:
propagatedownload.cpp:1303 "Rename failed: .../00/.Q.CONSEGNA ENEL.dwg.~2024 => .../00/Q.CONSEGNA ENEL.dwg"
filesystem.cpp:880 Renaming temp file to final failed: "WindowsError: 5: Accesso negato."
In one morning, a single user's client made 46 LOCK/UNLOCK calls on .dwg/.schx/.upex files. Each one changed the etag and could trigger this.
Additional observations
- Lock files listed in the exclude list (
*.dwl,*.dwl2,~$*) still trigger the auto-lock. Excluding them does not avoid the problem. ~$<name>.schx, a lock file written by ePlus (an AutoCAD-based electrical CAD), is treated like an Office lock file, so.schxand.upexfiles get auto-locked too.- There is no client setting to disable auto-locking. The only workaround we found is to disable
files_lockon the server (occ app:disable files_lock), which also removes locking for Office files.
Expected behaviour
The etag change on LOCK/UNLOCK is probably intended on the files_lock side, so that other clients pick up the new lock state. So we are reporting this against the desktop client:
- a lock-only etag change (same checksum, size and mtime) should not be treated as a content change. At the very least the client that holds the lock, or just released it, should not re-download the file or create a conflict copy;
- it would also help to have a client option (or a server-side setting) to disable auto-locking without disabling
files_lockcompletely.
If the maintainers think files_lock should not change the etag, we can open a separate issue in nextcloud/files_lock.
Versions
- Desktop client: 35.0.3 (build 20261104, commit 809fadb), Windows 11 26H2, virtual files (wincfapi). Previous client 4.0.6 did not show the issue (no AutoCAD lock detection).
- Server: Nextcloud 35.0.2 (AIO),
files_lock35.0.1, PostgreSQL, Redis. - Related: nextcloud/desktop#10379 (AutoCAD lock file detection); nextcloud/files_lock
lib/Service/LockService.php(propagateEtag).
there should be a fix in place already. it was changed in NextcloudKit. need to check...
Thanks! Could you point me to the NextcloudKit change (PR/commit)? As far as I know NextcloudKit is used by the iOS app and the macOS File Provider, while this report is about the Windows client 35.0.3 with virtual files (wincfapi). Is the fix also in the classic sync engine (libsync), and in which Windows release? Happy to test a daily/RC build.