{"record":{"id":"45e33ec0f5f852af","repo":"denoland/deno","slug":"couldn-t-consume-wasmstreamingresource","errorCode":null,"errorMessage":"Couldn't consume WasmStreamingResource.","messagePattern":"Couldn't consume WasmStreamingResource\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/core/ops_builtin.rs","lineNumber":291,"sourceCode":"    self.0.borrow_mut().on_bytes_received(&buf);\n    Box::pin(std::future::ready(Ok(WriteOutcome::Full { nwritten })))\n  }\n\n  fn write_all(self: Rc<Self>, view: BufView) -> AsyncResult<()> {\n    self.0.borrow_mut().on_bytes_received(&view);\n    Box::pin(std::future::ready(Ok(())))\n  }\n\n  fn close(self: Rc<Self>) {\n    // At this point there are no clones of Rc<WasmStreamingResource> on the\n    // resource table, and no one should own a reference outside of the stack.\n    // Therefore, we can be sure `self` is the only reference.\n    match Rc::try_unwrap(self) {\n      Ok(wsr) => {\n        wsr.0.into_inner().finish();\n      }\n      _ => {\n        panic!(\"Couldn't consume WasmStreamingResource.\");\n      }\n    }\n  }\n}\n\n/// Feed bytes to WasmStreamingResource.\n#[op2(fast)]\npub fn op_wasm_streaming_feed(\n  state: Rc<RefCell<OpState>>,\n  #[smi] rid: ResourceId,\n  #[buffer] bytes: &[u8],\n) -> Result<(), ResourceError> {\n  let wasm_streaming = state\n    .borrow_mut()\n    .resource_table\n    .get::<WasmStreamingResource>(rid)?;\n\n  wasm_streaming.0.borrow_mut().on_bytes_received(bytes);","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/core/ops_builtin.rs#L273-L309","documentation":"WebAssembly.compileStreaming is backed by a WasmStreamingResource in Deno's resource table. On close, the runtime assumes it holds the only Rc reference and consumes it via Rc::try_unwrap to finish the stream; if another reference exists, the unwrap fails and the process panics. Users never touch this resource through the documented API, so hitting it implies manual resource manipulation or an internal lifecycle bug.","triggerScenarios":"Manually closing the streaming resource id (Deno.resources()/Deno.close on the rid of a pending compileStreaming), or internal code holding a clone while close runs — a lifecycle misuse rather than a normal API sequence.","commonSituations":"Tools that enumerate and aggressively close all open Deno resources; aborted or pipelined wasm compilations where cleanup races a live reference; deno_core bugs in the streaming lifecycle (fixed at the core level when found).","solutions":["Never close wasm streaming resources manually — await the compileStreaming promise instead","Let abort/failure paths settle before touching resource ids","If the panic occurs without any manual resource management, update Deno and report the reproducer","Minimize with a plain `await WebAssembly.compileStreaming(fetch(url))` loop when reporting"],"exampleFix":"// before — force-closing resources while a compile is pending\nconst p = WebAssembly.compileStreaming(fetch(\"./mod.wasm\"));\nfor (const [rid] of Object.entries(Deno.resources())) Deno.close(Number(rid));\n\n// after — await the promise; the runtime closes the resource itself\nconst mod = await WebAssembly.compileStreaming(fetch(\"./mod.wasm\"));","handlingStrategy":"validation","validationCode":"// track in-flight compilations; never close their resources\nconst pending = new Set<Promise<unknown>>();\nfunction compile(url: string | URL) {\n  const p = WebAssembly.compileStreaming(fetch(url)).finally(() => pending.delete(p));\n  pending.add(p);\n  return p;\n}\nawait Promise.all(pending);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Deno.close on the rid of an in-flight compileStreaming","Avoid blanket close-all-resources cleanup loops while wasm compilations are pending","Let the runtime's own lifecycle manage wasm streaming resources"],"tags":["wasm","deno-core","resources","streaming-compiler"],"backgroundTag":"wasm-streaming-resource-misuse","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}