Skip to content

Fix race inflate - #120

Merged
mafintosh merged 6 commits into
mainfrom
fix-race-inflate
Oct 28, 2026
Merged

mafintosh merged 6 commits into
mainfrom
fix-race-inflate

Conversation

@lejeunerenard

Copy link
Copy Markdown
Contributor

The .inflate() method can possibly return null because of the value being inflated being cleared from the pointer when calling .bump(). Seems most likely while there are parallel inflations.

The test makes this edgecase consistent by setting the cache to maxCacheSize of 0. This causes a single inflation to evict it's own value before returning it.

Made with help from AI.

The `ptr.value` could theoretically be cleared by:
1. sharing the pointer value with another request
2. being schedule after the other request completes, but causes the
   cache to clear the value in the interim because of age etc
The cached value can be cleared theoretically because of the `.bump()`
in `inflate()`. The new test makes this consistent by setting the
maxCacheSize to `0` so every bump gc's the cached value.
@lejeunerenard
lejeunerenard requested a review from a team October 28, 2026 02:41
lejeunerenard and others added 4 commits October 28, 2026 00:03
The inflate wrapper could re-insert a pointer that lost its value between
the inner inflate and its own bump, so put the value back first.

The cache now evicts an existing pointer for the same id on first insert,
unless a write has it pinned. Eviction lives in _remove, which reports
whether the node was pinned, and gc, empty and bump act on that. Removing
the newest node now promotes the previous newest instead of the oldest.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mafintosh
mafintosh merged commit f6d115a into main Oct 28, 2026
4 checks passed
@mafintosh
mafintosh deleted the fix-race-inflate branch October 28, 2026 08:49
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