Skip to content

fix(jsc): fix data race on VirtualMachine::is_shutting_down #30946

Open
DagmawiKK wants to merge 1 commit into
oven-sh:mainfrom
DagmawiKK:claude/fetch-atomic-shutdown
Open

fix(jsc): fix data race on VirtualMachine::is_shutting_down #30946
DagmawiKK wants to merge 1 commit into
oven-sh:mainfrom
DagmawiKK:claude/fetch-atomic-shutdown

Conversation

@DagmawiKK
Copy link
Copy Markdown

What does this PR do?

Fixes a data race on VirtualMachine::is_shutting_down.

is_shutting_down was a plain bool, 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 in global_exit().

The fix changes the field to AtomicBool:

  • Reads: load(Ordering::Acquire) guarantees that seeing true synchronizes-with the release store, making all prior teardown writes visible
  • Writes: store(true, Ordering::Release) prevents reordering of cleanup hooks past the flag

How did you verify your code works?

  • Build succeeds (bun run build) with no new warnings
  • bun bd test test/js/bun/http/serve.test.ts -t "should work" — 11 pass, 0 fail

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 56006a53-81fb-4321-988c-550fe66ad2d2

📥 Commits

Reviewing files that changed from the base of the PR and between 172afa5 and 430c6d0.

📒 Files selected for processing (3)
  • src/jsc/VirtualMachine.rs
  • src/jsc/web_worker.rs
  • src/runtime/cli/test_command.rs

Walkthrough

This PR converts the VirtualMachine.is_shutting_down shutdown flag from a plain bool to an AtomicBool. All read operations now use Ordering::Acquire and all write operations use Ordering::Release to ensure proper cross-thread synchronization semantics during VM shutdown across multiple code paths.

Changes

Atomic shutdown flag synchronization

Layer / File(s) Summary
Atomic shutdown contract and readers
src/jsc/VirtualMachine.rs
VirtualMachine.is_shutting_down field type changes from bool to AtomicBool. The is_shutting_down() accessor and script_execution_status() branch now perform Ordering::Acquire reads on the atomic field.
Shutdown flag writers across exit paths
src/jsc/VirtualMachine.rs, src/jsc/web_worker.rs, src/runtime/cli/test_command.rs
All shutdown signaling sites (global_exit(), WebWorker::shutdown(), and test command error paths) update the flag using store(true, Ordering::Release) instead of direct assignment, ensuring visibility to other threads.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: fixing a data race on VirtualMachine::is_shutting_down by converting it to AtomicBool.
Description check ✅ Passed The description covers both required template sections with detailed technical explanation of the data race issue, the fix implementation, and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant