Skip to content

Fix data race in _PersistentReference.withLock#209

Merged
stephencelis merged 3 commits into
pointfreeco:mainfrom
freak4pc:fix/withlock-data-race
Mar 26, 2026
Merged

Fix data race in _PersistentReference.withLock#209
stephencelis merged 3 commits into
pointfreeco:mainfrom
freak4pc:fix/withlock-data-race

Conversation

@freak4pc
Copy link
Copy Markdown
Contributor

We saw this super-hard-to-repro crash for a few users (it basically returns a 21 PB allocation for the buffer count because something gets corrupted along the way).

The defer block was reading self.value without holding the lock to pass to key.save. Another thread could acquire the lock and write a new value concurrently.

This fix captures the value under the lock using an inner defer so it is captured on both the success and throwing paths, preserving existing semantics.

freak4pc and others added 3 commits March 20, 2026 23:04
The defer block was reading self.value without holding the lock to pass
to key.save. Another thread could acquire the lock and write a new value
concurrently, causing a use-after-free on the COW buffer.

Capture the value under the lock using an inner defer so it is captured
on both the success and throwing paths, preserving existing semantics.
Copy link
Copy Markdown
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@stephencelis stephencelis merged commit 3533cb3 into pointfreeco:main Mar 26, 2026
@freak4pc freak4pc deleted the fix/withlock-data-race branch March 27, 2026 20:15
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.

3 participants