Skip to content

serialise singleton construction in FileLockMeta#581

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
dxbjavid:singleton-cache-lock
Jul 6, 2026
Merged

serialise singleton construction in FileLockMeta#581
gaborbernat merged 2 commits into
tox-dev:mainfrom
dxbjavid:singleton-cache-lock

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

FileLockMeta.call reads and writes its singleton cache without a lock, so two threads constructing the same is_singleton=True lock for a fresh path both miss the cache and each build their own instance. That quietly breaks the singleton guarantee callers lean on for reentrant locking across instances, so a later reentrant acquire on what should be the same lock can hit the deadlock check in acquire(), and the concurrent writes to the shared WeakValueDictionary are a race in their own right. ReadWriteLock and SoftReadWriteLock already take their _instances_lock around the get-or-create, so this brings the base metaclass in line.

dxbjavid and others added 2 commits July 3, 2026 23:55
Collapse the eight-argument construction call that _create_instance
duplicated at both call sites into a single params dict built once in
__call__, so the helper drops its PLR0913 signature down to three
parameters. Fix the codespell failure (serialise) and tighten the
serialisation comment.
@gaborbernat gaborbernat enabled auto-merge (squash) July 6, 2026 22:46
@gaborbernat gaborbernat merged commit a833dd9 into tox-dev:main Jul 6, 2026
33 checks passed
@dxbjavid

dxbjavid commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

TY!

@gaborbernat

Copy link
Copy Markdown
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants