Fix data race initializing AttrCursor::_value#557
Merged
Conversation
AttrCursor::_value and EvalCache::value were lazily initialized without any synchronization, while `nix flake check/show` call into cursors shared between evaluator threads (e.g. the flake outputs cursor used by every Leaf::derivation() call). Two threads could both see an empty RootValue and move-assign it concurrently, double-freeing a root value slot. Since the root value pool uses an intrusive freelist, a double free corrupts the freelist and makes a subsequent allocRootValueSlot() chase a garbage next pointer, crashing with EXC_BAD_ACCESS (e.g. at address 0x28, a Value discriminator word read as a Slot pointer). Wrap both members in Sync so initialization happens exactly once and concurrent callers block until the value is available. The lock is held while the value is computed; lock ordering is strictly child -> parent (and thunk waiting in parallel eval blocks on a condition variable, without work stealing), so this cannot deadlock. Note: AttrCursor::cachedValue has a similar unsynchronized lazy initialization pattern that still needs fixing. Assisted-by: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesEval-cache synchronization
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
cole-h
approved these changes
Jul 13, 2026
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.
Motivation
This field could be lazily initialized by multiple threads, clobbering each other's
RootValue. Since #546 this has been much more likely to lead to a crash. (PreviouslyRootValuewas anstd::shared_ptr, which was not safe either but unlikely to crash.)Context
Summary by CodeRabbit