fix(runtime): harden EXP-041 shared-provenance cluster#30972
fix(runtime): harden EXP-041 shared-provenance cluster#30972Dicklesworthstone wants to merge 2 commits 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 (2)
WalkthroughHandler.active_connections changes from plain usize to core::cell::Cell with helper methods updated to use Cell::get()/set() for saturating updates. Many modules drop local as_ctx_ptr helpers and import bun_ptr::AsCtxPtr; Interpreter tweaks raw-pointer construction. ChangesWebSocket Cell connection tracking
AsCtxPtr trait migration and pointer adjustments
🚥 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 |
Jarred-Sumner
left a comment
There was a problem hiding this comment.
This should be Cell<usize> instead of AtomicUsize, and the comment about using Cell should be deleted.
Replace the WebSocket active_connections shared-reference write with AtomicUsize and centralize the sibling context-pointer helper pattern identified by the UB audit. The counter uses relaxed saturating updates because the value is only a count; no synchronization contract is attached to it. Most sibling sites now use the existing bun_ptr::AsCtxPtr helper instead of repeating hand-written self-as-const-self casts. Interpreter keeps an inherent as_ctx_ptr intentionally so Box<Interpreter> callers still produce *mut Interpreter instead of *mut Box<Interpreter>. Refs oven-sh#30903. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
94707bb to
3b592ec
Compare
…view Per Jarred-Sumner's review on oven-sh#30972: replace AtomicUsize with Cell<usize> for WebSocket Handler::active_connections. The Handler struct is already !Send/!Sync (holds *mut c_void, JSValue, BackRef), and the counter is only touched on the JS thread, so Cell is the right primitive — no synchronization contract was attached to the original counter. Drops the read-modify-write fetch_update calls in favor of get + set, and the load(Relaxed) in active_sockets_count for plain get. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the review @Jarred-Sumner — addressed in 7ff8ba2.
|
|
@Jarred-Sumner quick follow-up on your requested change here: this branch now uses Verified with Does this match the shape you wanted, or would you prefer any further adjustment? |
References the UB audit PR: #30903
This is a focused follow-up fix for audit EXP-041.
What changed:
WebSocketServerContext::Handler.active_connectionsno longer mutates a plainusizethrough a pointer derived from&self. It is now anAtomicUsize, with relaxed saturating updates and relaxed reads. The value is only a count; no synchronization contract is attached to it.as_ctx_ptr(&self) -> *mut Self { ... }helper bodies called out in the EXP-041 cluster now route through the existingbun_ptr::AsCtxPtrhelper, so the shared-provenance contract lives in one audited place instead of being repeated across runtime wrappers.Interpreter::as_ctx_ptrintentionally remains an inherent method.Box<Interpreter>callers must produce*mut Interpreter, not*mut Box<Interpreter>; its body now usesptr::from_ref(self).cast_mut().Important scope note:
Verification run locally:
bun run fmt:rustcargo check -p bun_runtimebun run rust:check-all->10 ok, 0 failedBUN_DEBUG_QUIET_LOGS=1 bun bd -e ...smoke testBUN_DEBUG_QUIET_LOGS=1 bun bd test test/js/bun/websocket/websocket-server.test.ts -t sendTextgit diff --check origin/main..HEADrgsearch for the old WebSocket raw-write shape and oldself as *const Selfhelper bodies