← Back to Pull requests

gc: fix the store-buffering race in the parallel pool sweep handshake #65314

Open
unknown opened this pull request with 274 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 27, 2026 13:40 UTC
Author

gc_sweep_wait_for_all_pages stores NULL to gc_allocd_scratch and then waits for gc_n_threads_sweeping_pools to reach zero, while gc_sweep_pool_parallel increments the counter and then loads the scratch pointer. This is a store-then-load (store buffering) handshake: each side stores to one variable and then loads the other, and it is only correct if at least one side is guaranteed to observe the other's store. A seq_cst store followed by an acquire load of a different variable does not give that guarantee. On AArch64 targets with RCpc support (e.g. the macOS builds) it compiles to stlr followed by ldapr, and the load may be satisfied before the store is visible to other threads. The GC thread running the collection could then read zero while a late GC worker still read the old scratch pointer, and that worker would go on to sweep the already swept page lists. After a full sweep those pages have has_marked == 0, so every live page was pushed to the lazily freed pool, leading to a segfault in gc_setmark_pool_ in the next collection.

Both sides now have an explicit jl_fence() between their store and their load, as is done for the scheduler's sleep check, instead of relying on seq_cst operations. The waiting side keeps its acquire load, which is what orders it after the pages the workers pushed to the scratch stacks, and the worker acquires the scratch pointer, since it may be running on a request from an earlier collection. On macOS aarch64 the waiting side now compiles to str, dmb ish, ldapr. The remaining operations on these two variables (the stores that publish the scratch stacks and the decrement that ends a worker's sweep) are now release operations, using a new jl_atomic_fetch_add_release wrapper, so that nothing in the handshake relies on seq_cst operations.

I have not reproduced the crash locally; the fix is based on the analysis in the issue, which I checked against the source and the disassembly of the 1.13.4 macOS aarch64 binary.

This should be backported to 1.12 and 1.13.

Fixes #65301

This pull request was written with the assistance of generative AI.

🤖 Generated with Claude Code

Diff: 274 lines (+205 / -69) across 3 files Reviewer: Keno Review duration: 5232m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 274 lines diff across 3 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.336
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #65314"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 44.5% (MEDIUM) · Higher = larger blast radius
44.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 23.7% · Safe to merge
23.7%