{"record":{"id":"8a426a7b594efaba","repo":"denoland/deno","slug":"a-writable-stream-is-not-associated-with-the-write","errorCode":null,"errorMessage":"A writable stream is not associated with the writer","messagePattern":"A writable stream is not associated with the writer","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/web/06_streams.js","lineNumber":7529,"sourceCode":"    this[_brand] = _brand;\n    setUpWritableStreamDefaultWriter(this, stream);\n  }\n\n  /** @returns {Promise<void>} */\n  get closed() {\n    try {\n      webidl.assertBranded(this, WritableStreamDefaultWriterPrototype);\n    } catch (err) {\n      return PromiseReject(err);\n    }\n    return this[_closedPromise].promise;\n  }\n\n  /** @returns {number} */\n  get desiredSize() {\n    webidl.assertBranded(this, WritableStreamDefaultWriterPrototype);\n    if (this[_stream] === undefined) {\n      throw new TypeError(\n        \"A writable stream is not associated with the writer\",\n      );\n    }\n    return writableStreamDefaultWriterGetDesiredSize(this);\n  }\n\n  /** @returns {Promise<void>} */\n  get ready() {\n    try {\n      webidl.assertBranded(this, WritableStreamDefaultWriterPrototype);\n    } catch (err) {\n      return PromiseReject(err);\n    }\n    return this[_readyPromise].promise;\n  }\n\n  /**\n   * @param {any} reason","sourceCodeStart":7511,"sourceCodeEnd":7547,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/06_streams.js#L7511-L7547","documentation":"TypeError thrown by the WritableStreamDefaultWriter.desiredSize getter when this[_stream] is undefined (ext/web/06_streams.js). A writer only references its stream while it holds the lock; after releaseLock() (or after the stream errors/finalizes and the association is dropped), desiredSize can no longer be computed and the getter throws.","triggerScenarios":"writer.releaseLock() followed by reading writer.desiredSize; inspecting desiredSize after the stream was aborted/errored far enough to detach the writer; storing a writer past its lock lifetime and polling its desiredSize.","commonSituations":"Backpressure checks in cleanup/monitoring code that run after releaseLock; loops that release the lock on error and then log desiredSize for diagnostics; using one writer object after re-acquiring with getWriter() on the same stream.","solutions":["Read desiredSize before calling releaseLock(), while the writer still holds the lock.","After releasing, call stream.getWriter() again to get a valid writer before querying desiredSize.","Track the released state in your own variable and skip desiredSize queries once released.","Wrap the access in try/catch TypeError when the lock state cannot be proven."],"exampleFix":"// before\nconst writer = ws.getWriter();\nwriter.releaseLock();\nconsole.log(writer.desiredSize); // TypeError: no stream associated\n\n// after\nconst writer = ws.getWriter();\nconst size = writer.desiredSize; // read while locked\nwriter.releaseLock();","handlingStrategy":"try-catch","validationCode":"// Track the lock yourself: after releaseLock() the writer is inert.\nlet released = false;\nfunction desiredSizeOrZero(writer) {\n  if (released) return 0; // or null per your backpressure convention\n  return writer.desiredSize;\n}\n// ... on cleanup: released = true; writer.releaseLock();","typeGuard":null,"tryCatchPattern":"let size;\ntry {\n  size = writer.desiredSize;\n} catch (err) {\n  if (err instanceof TypeError && /not associated with the writer/.test(err.message)) size = null;\n  else throw err;\n}","preventionTips":["Read desiredSize before releaseLock(), in the same critical section.","Never reuse a writer object after releasing; call getWriter() fresh.","Keep a `released` flag alongside the writer in wrapper classes."],"tags":["streams","writable-stream","writer","backpressure"],"backgroundTag":"released-writer-access","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}