{"record":{"id":"b7a6c456a2e7c1a9","repo":"denoland/deno","slug":"epipe","errorCode":"EPIPE","errorMessage":"This socket has been ended by the other party","messagePattern":"This socket has been ended by the other party","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/net.ts","lineNumber":975,"sourceCode":"  if (!this.writableEnded) {\n    return FunctionPrototypeCall(\n      Duplex.prototype.write,\n      this,\n      chunk,\n      encoding as BufferEncoding | null,\n      // @ts-expect-error Using `call` seem to be interfering with the overload for write\n      cb,\n    );\n  }\n\n  if (typeof encoding === \"function\") {\n    cb = encoding;\n    encoding = null;\n  }\n\n  const err = genericNodeError(\n    \"This socket has been ended by the other party\",\n    { code: \"EPIPE\" },\n  );\n\n  if (typeof cb === \"function\") {\n    defaultTriggerAsyncIdScope(this[asyncIdSymbol], nextTick, cb, err);\n  }\n\n  if (this._server) {\n    nextTick(() => this.destroy(err));\n  } else {\n    this.destroy(err);\n  }\n\n  return false;\n}\n\nfunction _tryReadStart(socket: Socket) {\n  // Not already reading, start the flow.\n  debug(\"Socket._handle.readStart\");","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/net.ts#L957-L993","documentation":"Deno's node:net polyfill replaces Socket.write with _writeAfterFIN (net.ts:948-989): when the peer sent a FIN the socket ends its writable side, and any later write while writableEnded is true produces genericNodeError('This socket has been ended by the other party') with code EPIPE. The callback (if given) receives the error on the next tick; otherwise the socket is destroyed with it — server-side sockets on nextTick, client sockets immediately.","triggerScenarios":"Calling socket.write() after socket.end() (often triggered automatically when the 'end' event fires on FIN); an HTTP handler writing a response after the client disconnected; keepalive connections reused after the peer half-closed; pipelined writes queued behind an end().","commonSituations":"Slow handlers racing client aborts; proxies forwarding upstream data after the downstream closed; log-shipping clients that keep writing after the server closed the connection; missing 'close' listeners that would stop producers.","solutions":["Guard every write: skip when socket.writableEnded or socket.destroyed is true.","Always pass a write callback (or handle the 'error' event) so the EPIPE surfaces as data, not an uncaught exception.","Stop producers on 'end'/'close' — detach pipelines once the socket can no longer carry data.","For request/response protocols, finish writes before the handler returns and let the framework call end()."],"exampleFix":"// before\nsock.on('data', (chunk) => sock.write(ack(chunk)));\n// peer sends FIN -> end() -> next write: EPIPE\n// 'This socket has been ended by the other party'\n\n// after\nsock.on('data', (chunk) => {\n  if (sock.writableEnded || sock.destroyed) return; // peer hung up\n  sock.write(ack(chunk), (err) => { if (err) sock.destroy(); });\n});","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"/** True while the socket can still accept writes. */\nfunction socketWritable(sock) {\n  return !sock.destroyed && !sock.writableEnded && sock.writable;\n}","tryCatchPattern":"sock.write(data, (err) => {\n  if (err && err.code === 'EPIPE') {\n    // peer already ended/destroyed the socket: stop producing and close cleanly\n    stopProducers();\n    sock.destroy();\n  }\n});","preventionTips":["Check socket.writableEnded/destroyed before every write","Always pass a write callback or subscribe to 'error' so EPIPE is data, not a crash","Stop producers on 'end' and 'close' events","Finish response writes inside the handler; never write from timers after the peer may have gone"],"tags":["deno","node-compat","net","socket","epipe","write-after-end"],"backgroundTag":"broken-pipe","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"}