Require the isolate lock for jsg::Rc, jsg::Weak and jsg_cpp::Ref #8319
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 350 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8319"
general
weight: 0.35
nathanwhit
Only the isolate lock protects a resource's state: the reference counts of a jsg::Rc and its Wrappable, and the resource's Cells and RefCells. Today nothing enforces that. A jsg::Rc can be dereferenced and cloned without the lock, so a thread that holds one can read the resource or change its counts while another thread holds the lock. That's a data race, which is undefined behavior, and today safe code can cause it.
This PR makes the lock the only way to reach that state.
What changes
Why this is safe
As a result, jsg::Rc, jsg::Weak and jsg_cpp::Ref are Send for a Send resource: on a thread without the lock, all you can do with one is drop it. The argument is written up as safety rule 5 in src/rust/jsg/README.md.
Tests
- every lock-taking operation panics under another isolate's lock;
- detaching a reference from another isolate panics, and another isolate's GC leaves it alone;
- concurrent unlocked drops wait for the lock;
- teardown destroys a held jsg_cpp::Ref's C++ object before Dispose(), and one kept past teardown can still be dropped.