Repository navigation
webcore: make object URL blob stores safe to share across workers - #31487
Jarred-Sumner wants to merge 4 commits into
Conversation
URL.createObjectURL and resolveObjectURL/fetch(blob:)/new Worker(blob:) previously shared one Blob store between the registry entry and every caller, including callers on other worker threads. Renaming a blob via new File([blob], name), the cached file stat, and the is-all-ascii flag all wrote into that shared store, so a blob resolved in one worker could observe (and race) mutations made in another, and later resolutions reflected post-registration renames. Hand out a deep-duped store, an owned content type, and an isolated name on both sides of the registry boundary instead, so registry entries and resolved blobs never share mutable state. Resolution still returns the same contents, type, and name, and now matches Node's behavior of not reflecting post-registration mutations into later resolutions. Also switch store::S3.credentials from Rc to Arc, since blob stores are reachable from more than one thread.
|
Updated 8:54 PM PT - May 27th, 2026
✅ @autofix-ci[bot], your commit 6b3e7905a6ca8cfbdd1ccde941f485d0149407ed passed in 🧪 To try this PR locally: bunx bun-pr 31487That installs a local version of the PR into your bun-31487 --bun |
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
WalkthroughThis PR introduces Store::deep_dupe() to create thread-safe, isolated blob snapshots with independently owned payloads. ObjectURLRegistry uses this mechanism when registering and resolving blobs so blobs returned by resolveObjectURL remain isolated from concurrent store mutations. Tests validate isolation in single-thread and multi-worker scenarios. ChangesCross-thread blob isolation mechanism
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
- deep-copy S3 credentials in Store::deep_dupe instead of sharing the Rc - take the store snapshot after releasing the registry lock in resolve - point resolved blobs at the resolving global
|
Fixed in e5f8ef2 by dropping the Rc→Arc change entirely (option b). S3Credentials holds a non-atomic intrusive RefCount (Cell + thread-lock), so Arc was both lint-rejected and not actually sound. Store::deep_dupe now deep-copies the credentials value into a fresh Rc owned solely by the snapshot (S3Credentials::Clone already deep-copies its Box<[u8]> fields and resets the refcount), so the registry copy still shares no state with the source blob; all other Rc usage is reverted to match main. cargo clippy -p bun_jsc -p bun_runtime is clean locally. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/webcore/ObjectURLRegistry.rs`:
- Around line 109-126: resolve_and_dupe currently returns a Blob still seeded
with the registry entry's stale global_this; change resolve_and_dupe to accept a
&JSGlobalObject (or a pointer) so it can bind the resolving global: after
creating copy via dupe_without_store_snapshot(&map.get(&uuid.bytes)?.blob) set
copy.global_this to std::ptr::from_ref(global_object) before calling
snapshot_store(©) and returning it, then update resolve_and_dupe_to_js to
call the new resolve_and_dupe(...) and remove the manual global_this patch
there; keep references to uuid_from_pathname, dupe_without_store_snapshot,
snapshot_store, Blob, resolve_and_dupe_to_js and map.get when making the edits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 95e942fc-b6b7-4555-8b0a-eb96028ffcf3
📒 Files selected for processing (2)
src/jsc/webcore_types.rssrc/runtime/webcore/ObjectURLRegistry.rs
Jarred-Sumner
left a comment
There was a problem hiding this comment.
This is not correct. We should fix the specific fields which are not threadsafe. The RefCount for Store is threadsafe. We should not need to clone the bytes.
|
@robobun adopt |
|
✅ Adopted & verified — cross-worker object-URL isolation fix holds up end to end. Gate (debug/ASAN build, both ways):
Root cause confirmed: Linked the issue it closes ( |
|
Note from deduping the #30800 PRs: this branch keeps |
Fixes #30800
What
URL.createObjectURLstores aBlobin the process-globalObjectURLRegistry, andresolveObjectURL/fetch("blob:…")/new Worker("blob:…")handed that same backingStoreout to every caller — including callers on other worker threads, since the registry is shared across workers. The store is mutable through any holder (new File([blob], name)rewritesstored_name,.text()caches the is-all-ascii flag, file-backed blobs cache stat results), so a blob resolved in one worker could observe renames made concurrently in another worker, and later resolutions reflected mutations made after registration — which Node does not do.This PR makes both sides of the registry boundary hand out snapshots instead:
Store::deep_dupe()builds a fresh store:Bytescontents andstored_nameare copied,Filepaths are re-owned with the lazily-derived stat fields reset, and S3 keys are re-owned while the (immutable) credentials are shared viaArc.ObjectURLRegistrystores a snapshot atcreateObjectURLand returns a snapshot from every resolution, with the blob'scontent_typeandnamealso owned by the copy. The registry's own entry is only touched under the registry mutex.store::S3.credentialsswitches fromRc<S3Credentials>toArc<S3Credentials>, since a store held by the registry is reachable from more than one thread.Send/Synccomments onBlob/StoreRefare rewritten to state this invariant.Behavior notes
createObjectURL, or to a resolved blob (e.g.new File([resolved], "renamed.txt")), no longer show up in later resolutions. Node already behaves this way (it never reflects post-registration changes, and does not expose object URLs toworker_threadsat all).Memory tradeoff
Bytes-backed blobs are now copied once at
URL.createObjectURLand once per resolution (resolveObjectURL,fetch("blob:"),new Worker("blob:")) instead of refcount-shared. Negligible for the common worker-bootstrap / small-payload cases, but for very large blobs kept in the registry it roughly doubles peak memory while both the registry entry and a resolved copy are alive. The lower-memory alternative is to keep sharing the store and make the shared fields safe in place (atomicis_all_ascii,has_one_ref()-gated stat caching, never rewriting a shared store'sstored_name); that avoids the copies but keeps the store's data shared across threads and requires auditing every present and futuredata_mut()caller. Happy to switch to that shape if the copies are a concern.Tests
test/js/node/buffer-resolveObjectURL.test.ts: resolutions stay isolated from laternew File([blob], name)renames. Fails on 1.4.0 (the rename shows up in the next resolution), passes here. Matches Node.test/js/web/workers/worker_blob.test.ts: one worker repeatedly renames/reads its resolved copies while another resolves the same URL and checks name/type/contents — a sequenced phase (fails on 1.4.0: the other worker's rename is visible) plus a bounded concurrent phase exercising simultaneous access from two workers.bun run rust:check-allpasses for all 10 targets.