Repository navigation
fix(close): release the file lock when no other user is still editing - #9603
Draft
PeterPablo wants to merge 1 commit into
Draft
PeterPablo wants to merge 1 commit into
PeterPablo wants to merge 1 commit into
Conversation
`ApiService::close()` cleaned up the document context — and with it the
`files_lock` row — only when `getActiveSessions()` was empty. That is not the
same as "nobody is editing": the method counts every session row younger than
`SESSION_VALID_TIME` (5 minutes), and a reload of the editor leaves such rows
behind. Closing the freshest session therefore skipped the cleanup while a
leftover row of the *same* user kept the document "active".
Measured with the Nextcloud Notes app on Android, note opened through Direct
Editing, six session rows for one document, all the same user, the newest 13 s
old when its own close ran:
POST /apps/text/session/<id>/close 200
PUT /apps/notes/api/v1/notes/<id> 423
"…is locked, existing lock on file: files_lock/0f01f381-…"
oc_files_lock 1 row, still there
The file stayed locked, so the user could not rename or move the note — for
hours, until somebody released the row by hand. A close whose own row cannot be
matched leaves that row behind too, so the same gate fails for a second reason.
The lock exists to warn other people, so ask about them:
* `SessionService::hasRecentSessionsOfOtherUsers()` — any non-guest session of a
different user with contact in the last 60 s (a live editor pushes every few
seconds, so the window separates "somebody is typing" from leftovers);
* `close()` cleans up when no session is left **or** when no other user has been
active. Closing one of several tabs of the same user no longer skips it.
Assisted-by: DeepSeek:deepseek-v4.1-flash-1017
Signed-off-by: PeterPablo <4340267+PeterPablo@users.noreply.github.com>
PeterPablo
force-pushed
the
fix/release-lock-when-last-editor-leaves
branch
from
November 18, 2026 20:40
e8998c6 to
218747e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ApiService::close()released the file lock only whengetActiveSessions()came back empty — and that method counts every session row younger thanSESSION_VALID_TIME(5 minutes). A reload of the editor leaves such rows behind, so closing the freshest session skippedcontext->cleanup()and thefiles_lockrow survived. The document then cannot be written or renamed by anyone until somebody releases the row by hand — the symptom described in #9042.Measured on 35.0.2 with the Notes app (Direct Editing → Text in a WebView), one note, six session rows, all the same user, the newest 13 s old when its own close ran:
Two ways the gate fails, and both are ordinary:
Change
The lock protects other people, so ask about them instead of about rows:
SessionService::hasRecentSessionsOfOtherUsers($documentId, $userId, $graceSeconds = 60)— any non-guest session of a different user with contact inside the window;ApiService::close()cleans up when no session is left or when no other user has been active. Consequence: closing one of several tabs of the same user now releases the lock too — which is the intended behaviour, the user is done with that document.60 s because a live editor pushes every few seconds; that window separates "somebody is typing" from "these rows are leftovers".
Verified
Same device, same unpatched Notes app, with this change applied to a live instance:
Repeated: edit → close → rename, several times in a row, no lock left behind.
php -lclean on both files.Honest limits, and where I would like an opinion
SessionServicecan be unit-tested with the existing mocks, and I will add one if you tell me which shape you want (the repo hastests/Unit/Service/LockServiceTest.php-style mocks, but no test forApiService). I did not want to ship an unrun test.close()still needs thegetUser() ?? getSessionUser()fallback from599abe6for a token-driven client to reach this code at all — that part is already onmain.Refs #9042
#AI-ASSISTED (DeepSeek V4.1 Flash 1017)
Assisted by DeepSeek:deepseek-v4.1-flash-1017