Skip to content

Locking a file because a client *opened* it is the wrong design: every "stale Text lock" bug comes from it #9628

Done

Description

@AlpSha

Every few weeks another "file stuck as Locked by Text" bug is filed: #8769, #8858, #9042, #9354, #2760, nextcloud/ios#4225, nextcloud/files_lock#1297, nextcloud/files_lock#198. There are also feature requests that only exist to clean up after it: nextcloud/files_lock#52 and nextcloud/files_lock#764 (let admins unlock files), and nextcloud/files_lock#240 (bulk unlock). Fixing them one at a time won't end this. They all come from one design decision, and they will keep coming until that decision is reversed.

What happens today: I open a Markdown file in the iOS app to read it. Text takes an exclusive app lock on the file. From then on, every other client that tries to write the file gets 423 Locked, including my own desktop client. The lock is released only if the client that opened the file says goodbye cleanly. The lock has no expiry (ttl <= 0 means infinite in FileLock::getETA()). Text's own cleanup job garbage-collects the dead session but never releases its lock. The file's owner can't remove it either, because it's an app-owned lock, so the only way out is occ. On my instance this produced 10 stale locks in under three months, each one followed by a sync conflict.

Why the design is wrong, not just buggy:

  1. Opening is not writing. A reader takes a lock that blocks every writer. No mainstream sync service — Dropbox, Google Drive, iCloud, OneDrive — makes viewing a file block other devices from updating it. A lock that is taken on open, before any edit exists, protects nothing. It just turns reading into a denial of service against your own devices.

  2. The lock depends on a client saying goodbye, which you can't rely on. A mobile app gets backgrounded, its webview is killed, the user swipes back, the network drops, the battery dies. That's how mobile works, not a rare edge case. Any design where state on the server stays correct only if the client sends a clean close will leak, and Text's history shows exactly that. The standard answer is a lease: a lock that has to be renewed to stay alive. Text already tracks client activity (oc_text_sessions.last_contact), yet the lock isn't tied to it, so the server knows a session is dead and keeps enforcing its lock anyway.

  3. It makes conflicts worse, not better. Without the lock, a concurrent desktop write gives a conflict copy. That's annoying but visible and recoverable. With the lock, the desktop gets 423 and retries forever. The file silently stops syncing in both directions, and the user still ends up with a conflict copy once the lock finally goes away. The lock swaps a recoverable problem for a silent, indefinite one.

  4. It hides the real gap instead of fixing it. Text already merges concurrent edits from several live editors in real time. The lock exists only because the desktop client and other WebDAV writers bypass that merge and overwrite whole files. The real fix is for those writes to go through the same merge (or a three-way merge against the last synced version), or to create a conflict copy on the server side. Instead, a file-wide lock was put around the gap, and every client — iOS, Android, Notes, Direct Editing, desktop "edit locally" — now has to perfectly handle a lock it never asked for.

  5. It fails closed against the file's owner. When the system gets confused, it should fail in a way the user can fix: expire the lock, or let the owner remove it. Here, a lock owned by an app outranks the user who owns the file.

What I'm asking for:

  • No lock just for opening a file. If a lock is needed at all, take it on the first actual edit, as a short lease that renews while the session is alive and expires on its own when the session dies. That means minutes at most, with no admin involved.
  • Release locks when sessions die. Text's cleanup must release the lock of any session it garbage-collects.
  • Let owners clear app locks. The owner of a file must always be able to remove a lock on it, from every client.
  • Fix the actual gap. In the longer term, make concurrent writes from WebDAV and the desktop client merge or create a conflict copy on the server, so this lock isn't needed at all.

Until then, the only workaround that actually removed the problem for me was disabling files_lock entirely. It shouldn't take that to stop reading a file from breaking sync.

Environment: Nextcloud 35.0.2 (Docker), Text 9.0.1, files_lock 35.0.1, iOS app 35.2.2.0, PostgreSQL + Redis, background jobs via cron.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions