fix(jsc): fix data race on VirtualMachine::is_shutting_down #30946
fix(jsc): fix data race on VirtualMachine::is_shutting_down #30946DagmawiKK wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR converts the ChangesAtomic shutdown flag synchronization
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What does this PR do?
Fixes a data race on
VirtualMachine::is_shutting_down.is_shutting_downwas a plainbool, written from the main JS thread and read from the HTTP background thread via&'static VirtualMachine. Under the Rust memory model this is undefined behavior. On ARM, the write may never propagate to the reading core without an atomic barrier, causing the HTTP thread to operate on JSC state (global_this,JSPromiseStrong) after the VM has begun destructing inglobal_exit().The fix changes the field to
AtomicBool:load(Ordering::Acquire)guarantees that seeingtruesynchronizes-with the release store, making all prior teardown writes visiblestore(true, Ordering::Release)prevents reordering of cleanup hooks past the flagHow did you verify your code works?
bun run build) with no new warningsbun bd test test/js/bun/http/serve.test.ts -t "should work"— 11 pass, 0 fail