Repository navigation
🐛 fix(rw): reject misplaced singleton - #1058
Merged
Merged
Conversation
A concurrent chdir could separate the cache key from the SQLite database opened by a new singleton. Reject the instance before caching it so later callers cannot receive a lock for another file. Fixes #1019
gaborbernat
marked this pull request as draft
November 20, 2026 20:22
gaborbernat
marked this pull request as ready for review
November 20, 2026 20:24
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.
ReadWriteLockresolved a relative path for its singleton cache key, then resolved it again while constructing the instance (old code). A concurrent working-directory change could make the instance open a different SQLite database. A later caller then reused that instance for the first path, allowing a second process to enter a write lock for the requested database. Construction now raises before caching an instance whose database path differs from its key. Fixes #1019.The working directory changed between path resolutions
os.chdir()changes the working directory for the process. The metaclass resolved the relative path before calling the constructor; the constructor resolved it again afterchdir(). The cache entry kept the first path, while the instance opened the second. The new path comparison refuses that entry before publishing it.sequenceDiagram participant W as constructing thread participant C as directory-changing thread participant M as singleton metaclass participant L as later caller W->>+M: construct from relative path M->>M: resolve cache key in state directory C->>C: chdir to spool directory M->>M: constructor opens database in spool directory alt Before rect rgb(255, 214, 214) M-->>W: cache under state key L->>M: request state database M-->>L: return lock for spool database end else After rect rgb(216, 243, 220) M-->>W: raise RuntimeError, leave cache empty end end deactivate MBehavior changes
A singleton constructor now raises
RuntimeErrorif its database path changes during construction. It may have created a database at the second path before detecting the mismatch; that file remains. Callers that change directories concurrently can retry with an absolute path.Reported by the November 2026 filelock review: ANT-2026-E82KKN0V.