fix(desktop): serialize session persistence - #745
Open
imMamdouhaboammar wants to merge 1 commit into
Open
Conversation
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
Desktop session persistence used one deterministic temp path per session (
<sid>.json.tmp) while releasingself.lockbefore disk I/O. Two threads persisting the same session could therefore write/replace the same temp file concurrently. A separate deletion race also allowed a late worker persist to recreate a session JSON after the session had been deleted from manager state.Root cause
_persist_session()only heldself.lockwhile building the data snapshot, then performedtmp.write_text()andos.replace()unlocked._delete_session_file()also performed its filesystem operation without the same lock, and_persist_session()did not verify that theSessionobject was still registered before writing.Fix
RLockheld across the session snapshot, temp write, and atomic replaceself.sessions.get(s.id) is not s, preventing stale workers from recreating deleted sessionsThis preserves the existing per-session JSON format and atomic replace strategy.
Regression coverage
<sid>.json.tmpSessionobject cannot recreate its JSON filedesktop_bridge.pyonly inside the unittest class lifecycle, uses an isolated temporaryGA_ROOT, restoressys.argvandsys.modules, and does not leave import-time global state behindVerification
TDD was performed on a separate validation branch:
31164526542failed both targeted cases on currentmainFileNotFoundErrorfromos.replace_persist_session()recreated the file afterdelete_session()31164598932: compile, both deterministic concurrency regressions, andgit diff --check31165250013passed compile, both regressions, andgit diff --checkmainas one clean commit containing the production fix plus the isolated regression testScope
main