Title: http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0 · Issue #65677 · nodejs/node · GitHub
Open Graph Title: http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0 · Issue #65677 · nodejs/node
X Title: http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0 · Issue #65677 · nodejs/node
Description: Version v26.8.1 and v24.20.0 (official binaries). The regression starts between v26.2.0 and v26.3.0; v24.18.0 also passes. See the comparison below. Platform macOS, Darwin 25.6.0, arm64. Subsystem http2, stream (eos() and Readable async ...
Open Graph Description: Version v26.8.1 and v24.20.0 (official binaries). The regression starts between v26.2.0 and v26.3.0; v24.18.0 also passes. See the comparison below. Platform macOS, Darwin 25.6.0, arm64. Subsystem ...
X Description: Version v26.8.1 and v24.20.0 (official binaries). The regression starts between v26.2.0 and v26.3.0; v24.18.0 also passes. See the comparison below. Platform macOS, Darwin 25.6.0, arm64. Subsystem ...
Opengraph URL: https://github.com/nodejs/node/issues/65677
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0","articleBody":"### Version\n\nv26.8.1 and v24.20.0 (official binaries). The regression starts between v26.2.0 and v26.3.0; v24.18.0 also passes. See the comparison below.\n\n### Platform\n\nmacOS, Darwin 25.6.0, arm64.\n\n### Subsystem\n\n`http2`, `stream` (`eos()` and Readable async iteration)\n\n### What steps will reproduce the bug?\n\nSave this as `repro-http2-premature-close.mjs` and run it with `node repro-http2-premature-close.mjs`. It uses only Node built-in modules, localhost, and an ephemeral port. No proxy or third-party dependency is needed.\n\n```js\n// Run with an unmodified Node binary: node repro-http2-premature-close.mjs\n// Uses only built-in modules, localhost, and an ephemeral port.\nimport assert from 'node:assert/strict';\nimport { once } from 'node:events';\nimport http2 from 'node:http2';\nimport { setImmediate } from 'node:timers/promises';\n\nconst server = http2.createServer();\nserver.on('stream', (stream) => {\n stream.resume();\n stream.on('end', () => {\n stream.respond({ ':status': 200 }, { waitForTrailers: true });\n stream.on('wantTrailers', () => stream.sendTrailers({ 'grpc-status': '0' }));\n stream.end('complete response');\n });\n});\nserver.listen(0, '127.0.0.1');\nawait once(server, 'listening');\nconst session = http2.connect(`http://127.0.0.1:${server.address().port}`);\n\ntry {\n await once(session, 'connect');\n const request = session.request({ ':method': 'POST' });\n const response = once(request, 'response');\n request.end('request');\n await response;\n\n // Delay consuming the response until HTTP/2 reports a normal stream close.\n // The complete response body is still buffered, and the stream is not destroyed.\n const deadline = Date.now() + 2_000;\n while (!request.closed && Date.now() \u003c deadline) await setImmediate();\n assert.equal(request.closed, true);\n assert.equal(request.rstCode, 0);\n assert.equal(request.destroyed, false);\n assert.equal(request.readableLength, Buffer.byteLength('complete response'));\n\n let body = '';\n for await (const chunk of request) body += chunk.toString();\n assert.equal(body, 'complete response');\n console.log(`${process.version}: PASS`);\n} finally {\n session.destroy();\n await once(session, 'close');\n server.close();\n await once(server, 'close');\n}\n```\n\n### How often does it reproduce? Is there a required condition?\n\nThe equivalent direct-connection test failed on all 20 attempts in each affected version listed below. The required condition is that iteration starts after the HTTP/2 stream closes normally, while the response body is still buffered.\n\nBefore reading, the reproduction asserts `closed === true`, `rstCode === 0`, `destroyed === false`, and that all 17 response bytes remain in `readableLength`. It does not destroy the stream before consuming it; session destruction is only in cleanup.\n\nWithout intentionally waiting for this state, the failure depends on scheduling. Downstream gRPC calls through proxy/Duplex transports exposed it, but the reproduction removes both the proxy and the gRPC library.\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`for await` consumes `complete response` successfully and finishes without an error. The process exits with status 0, as it does on v24.18.0 and v26.2.0. The HTTP/2 stream closed normally and its complete response is still readable.\n\n### What do you see instead?\n\n`for await` throws `ERR_STREAM_PREMATURE_CLOSE`; the process exits with status 1. On v26.8.1:\n\n```text\nError [ERR_STREAM_PREMATURE_CLOSE]: Premature close\n at getEosOnCloseError (node:internal/streams/end-of-stream:98:14)\n at eos (node:internal/streams/end-of-stream:159:23)\n at start (node:internal/streams/readable:1425:15)\n at Object.next (node:internal/streams/readable:1574:23)\n```\n\nv24.20.0 fails with the same error through `getEosOnCloseError` / `eos` / `createAsyncIterator`.\n\n### Additional information\n\n**Version comparison** for the equivalent direct-connection reproduction, delaying consumption until `request.closed`:\n\n| Node version | Successful responses / attempts |\n| --- | --- |\n| 24.18.0 | 20 / 20 |\n| 24.20.0 | 0 / 20 |\n| 26.2.0 | 20 / 20 |\n| 26.3.0 | 0 / 20 |\n| 26.7.0 | 0 / 20 |\n| 26.8.1 | 0 / 20 |\n\nThe single-case script above was also verified separately with v24.18.0 and v26.2.0 (exit 0), and with v24.20.0, v26.3.0 and v26.8.1 (exit 1).\n\n**Suspected regression mechanism:** the version boundary and source comparison point to #62394, [cbee0de1cb](https://github.com/nodejs/node/commit/cbee0de1cb0cc2947d024bc1228c965ae115a55f), released in [v26.3.0](https://nodejs.org/en/blog/release/v26.3.0). The same change was backported as [5658c631fa](https://github.com/nodejs/node/commit/5658c631fa) in [v24.20.0](https://nodejs.org/en/blog/release/v24.20.0).\n\n`Http2Stream.closed` can be true after a normal protocol close while the readable body is still buffered. `eos()` now computes `immediateResult` before that buffer is consumed, then reports the captured premature-close error in a subsequent `process.nextTick()` callback. The previous implementation evaluated the close error on the next tick instead.\n\nA diagnostic comparison on v26.8.1, keeping its async iterator unchanged and only recomputing the close result inside the next-tick callback, changes the direct-connection test from 0/20 to 20/20 successful responses. That is evidence for the timing regression, not a proposed production monkey patch.\n\n**Related reports checked:** #63989 and #64098 concern HTTP/1.1 keep-alive / `node-fetch`. This reproduction uses core HTTP/2 with a normal protocol close, and also fails on v26.8.1 after those reports were resolved. #44866 is the older Web Stream termination hang addressed by #62394, rather than this new async-iteration failure.\n","author":{"url":"https://github.com/colinaaa","@type":"Person","name":"colinaaa"},"datePublished":"2026-08-31T11:14:30Z","url":"https://github.com/nodejs/node/issues/65677"}
| 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:34b10bc5-28f5-356a-5e7d-faf387c54387 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A15E:254F12:AD1062:DB1F0F:6B036A01 |
| html-safe-nonce | d2124c9163e62ebf45568bd413a53dfb5c280040ce5ceb09f202b6e89d972886 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTVFOjI1NEYxMjpBRDEwNjI6REIxRjBGOjZCMDM2QTAxIiwidmlzaXRvcl9pZCI6Ijg3MzkxMTM3MzI5OTY4MTk0NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4661e6c0cf9596c828e3213b95b36a00a43cbb849619928b77ea5cb32b9d8b97 |
| hovercard-subject-tag | issue:5299494957 |
| 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/65677/issue_layout |
| twitter:image | https://opengraph.githubassets.com/16676c0cb3e4de911056048b0950459318e338dc083337e6a2204367e4fe85af/nodejs/node/issues/65677 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/16676c0cb3e4de911056048b0950459318e338dc083337e6a2204367e4fe85af/nodejs/node/issues/65677 |
| og:image:alt | Version v26.8.1 and v24.20.0 (official binaries). The regression starts between v26.2.0 and v26.3.0; v24.18.0 also passes. See the comparison below. Platform macOS, Darwin 25.6.0, arm64. Subsystem ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | colinaaa |
| 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