Title: ERR_STREAM_PREMATURE_CLOSE after a complete chunked response when a keep-alive socket is destroyed (regression, 24.9–24.17 and 26.x) · Issue #64098 · nodejs/node · GitHub
Open Graph Title: ERR_STREAM_PREMATURE_CLOSE after a complete chunked response when a keep-alive socket is destroyed (regression, 24.9–24.17 and 26.x) · Issue #64098 · nodejs/node
X Title: ERR_STREAM_PREMATURE_CLOSE after a complete chunked response when a keep-alive socket is destroyed (regression, 24.9–24.17 and 26.x) · Issue #64098 · nodejs/node
Description: When an HTTP/1.1 server sends a complete response over a keep-alive connection and then abruptly destroys/resets the socket (instead of a graceful FIN), readers that wrap the response body in a stream-completion check (e.g. node-fetch@2)...
Open Graph Description: When an HTTP/1.1 server sends a complete response over a keep-alive connection and then abruptly destroys/resets the socket (instead of a graceful FIN), readers that wrap the response body in a str...
X Description: When an HTTP/1.1 server sends a complete response over a keep-alive connection and then abruptly destroys/resets the socket (instead of a graceful FIN), readers that wrap the response body in a str...
Opengraph URL: https://github.com/nodejs/node/issues/64098
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ERR_STREAM_PREMATURE_CLOSE after a complete chunked response when a keep-alive socket is destroyed (regression, 24.9–24.17 and 26.x)","articleBody":"When an HTTP/1.1 server sends a **complete** response over a keep-alive connection\nand then **abruptly destroys/resets the socket** (instead of a graceful FIN), readers\nthat wrap the response body in a stream-completion check (e.g. `node-fetch@2`) now\nreceive `ERR_STREAM_PREMATURE_CLOSE` — even though the full body was already delivered.\n\nThis is a regression that toggles across releases:\n\n| Node | result |\n|------|--------|\n| 24.0.0, 24.4.0, 24.8.0 | OK |\n| 24.17.0 (latest 24 LTS) | **ERR_STREAM_PREMATURE_CLOSE** |\n| 25.9.0 | OK (fixed on the 25 line) |\n| 26.3.1 (current) | **ERR_STREAM_PREMATURE_CLOSE** (re-regressed) |\n\nThe fix on the 25 line was apparently not backported to 24 LTS and has regressed in 26.\n\nIt reproduces in any environment (bare metal, plain Docker, `--network none` if deps are\npre-installed) — it is purely loopback (`127.0.0.1`), no external services involved.\n\n# Repro\n\nSee also [gist](https://gist.github.com/instilled/f9025ed03dc158a93028a593aa87b970).\n\n```js\n// repro.mjs — npm i node-fetch@2 && node repro.mjs\nimport net from \"node:net\";\nimport fetch from \"node-fetch\";\nimport { Agent } from \"node:http\";\n\nconst payload = JSON.stringify({ ok: true });\nconst hex = Buffer.byteLength(payload).toString(16);\n\nconst server = net.createServer((sock) => {\n sock.on(\"error\", () => {});\n sock.once(\"data\", () => {\n // Complete chunked response (terminating 0-chunk present)...\n sock.write(\n `HTTP/1.1 200 OK\\r\\nContent-Type: application/json\\r\\n` +\n `Transfer-Encoding: chunked\\r\\nConnection: keep-alive\\r\\n\\r\\n` +\n `${hex}\\r\\n${payload}\\r\\n0\\r\\n\\r\\n`\n );\n // ...then abruptly destroy the keep-alive socket (as some front-ends do).\n sock.destroy();\n });\n});\n\nserver.listen(0, async () => {\n const { port } = server.address();\n const agent = new Agent({ keepAlive: true });\n try {\n const r = await fetch(`http://127.0.0.1:${port}/`, { method: \"POST\", body: \"x\", agent });\n console.log(\"OK\", r.status, await r.text());\n } catch (e) {\n console.log(\"ERR\", e.code || e.message); // ERR_STREAM_PREMATURE_CLOSE on affected versions\n } finally {\n agent.destroy();\n server.close();\n }\n});\n```\n\nRun across versions, e.g.:\n\n```\nfor v in 24.8.0 24.17.0 25.9.0 26.3.1; do\n echo \"== node:$v ==\"\n docker run --rm node:$v-slim bash -c \\\n 'cd /tmp && npm init -y >/dev/null && npm i node-fetch@2 >/dev/null && node -e \"...\"' # or copy repro.mjs in\ndone\n```\n\n# Expected\n\nA response whose body is fully and correctly framed (complete chunked encoding with the\nterminating `0\\r\\n\\r\\n`) should resolve successfully. A subsequent abrupt socket close on a\nkeep-alive connection — after the response is complete — must not surface as a premature\nclose of the (already finished) body stream.\n\n# Actual\n\n`ERR_STREAM_PREMATURE_CLOSE` is raised on Node 24.9–24.17 and 26.x. The same code works on\n24.0–24.8 and 25.9.\n\n# Notes\n\n- `keepAlive: false` (or a graceful FIN via `socket.end()`) avoids it.\n- `node-fetch@2` is in maintenance, but it is unchanged across these runs — only the Node\n version differs — so the behavior change is on the Node side.\n","author":{"url":"https://github.com/instilled","@type":"Person","name":"instilled"},"datePublished":"2026-06-23T18:35:25Z","url":"https://github.com/nodejs/node/issues/64098"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04ab01be-9e0f-d297-5eac-359da840433a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC58:1ADDB0:2B22CF5:36A186E:6B037132 |
| html-safe-nonce | 82b4fea5ed5430d68c80c6a63e2bbd6f51fe83ce1ee8567c267bff07b0b9aae3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzU4OjFBRERCMDoyQjIyQ0Y1OjM2QTE4NkU6NkIwMzcxMzIiLCJ2aXNpdG9yX2lkIjoiNjQ4NDg0MTI3MjI3OTUyNzczMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8b6afd38608618798ad78d4d89642334743f87f25f1d7e59c7e644a7ef87f30d |
| hovercard-subject-tag | issue:4728549003 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/64098/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8d5d4d7a85eb9e641b961c2411e2a953f49d55187c660d9ff8b5661ec9825f6e/nodejs/node/issues/64098 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8d5d4d7a85eb9e641b961c2411e2a953f49d55187c660d9ff8b5661ec9825f6e/nodejs/node/issues/64098 |
| og:image:alt | When an HTTP/1.1 server sends a complete response over a keep-alive connection and then abruptly destroys/resets the socket (instead of a graceful FIN), readers that wrap the response body in a str... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | instilled |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width