Title: http: client stops forwarding socket `'drain'` to the request once the response is complete · Issue #67763 · nodejs/node · GitHub
Open Graph Title: http: client stops forwarding socket `'drain'` to the request once the response is complete · Issue #67763 · nodejs/node
X Title: http: client stops forwarding socket `'drain'` to the request once the response is complete · Issue #67763 · nodejs/node
Description: Version v20.20.2, v22.23.5, v24.22.3, v26.13.1 (all tested versions) Platform Linux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux (It must be noted this is th...
Open Graph Description: Version v20.20.2, v22.23.5, v24.22.3, v26.13.1 (all tested versions) Platform Linux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_6...
X Description: Version v20.20.2, v22.23.5, v24.22.3, v26.13.1 (all tested versions) Platform Linux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_6...
Opengraph URL: https://github.com/nodejs/node/issues/67763
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"http: client stops forwarding socket `'drain'` to the request once the response is complete","articleBody":"### Version\n\nv20.20.2, v22.23.5, v24.22.3, v26.13.1 (all tested versions)\n\n### Platform\n\n```text\nLinux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux\n\n(It must be noted this is the Hosts' command. The replication is done inside a Podman Container)\n```\n\n### Subsystem\n\nhttp\n\n### What steps will reproduce the bug?\n\nThe server answers as soon as it has the request headers, while the client is still writing a body with backpressure:\n\n```js\n'use strict';\n// node repro.js -> request never finishes (exit 1)\n// node repro.js fix -> forwards the socket's 'drain' to the request (exit 0)\nconst http = require('node:http');\nconst FIX = process.argv[2] === 'fix';\nconst BODY = 8 * 1024 * 1024;\n\nconst srv = http.createServer((q, r) => { r.writeHead(201, { 'Content-Length': '0' }); r.end(); q.resume(); });\nsrv.listen(0, '127.0.0.1', () => {\n const req = http.request({ port: srv.address().port, method: 'PUT', path: '/', headers: { 'Content-Length': BODY } }, (res) => {\n if (FIX) req.socket.on('drain', () => req.emit('drain'));\n res.resume();\n res.on('end', () => setTimeout(() => {\n console.log(`node ${process.version} fix=${FIX}: writableFinished=${req.writableFinished} writableNeedDrain=${req.writableNeedDrain}`);\n process.exit(req.writableFinished ? 0 : 1);\n }, 1500));\n });\n const chunk = Buffer.alloc(64 * 1024, 7);\n let left = BODY;\n (function write() {\n while (left > 0) {\n const n = Math.min(left, chunk.length); left -= n;\n if (!req.write(chunk.subarray(0, n))) return req.once('drain', write);\n }\n req.end();\n })();\n});\n```\n\n\n### How often does it reproduce? Is there a required condition?\n\nAlways with the script above. The required condition is that the response is completely parsed while the request is still waiting for `'drain'`.\n\nWith a server that replies only after reading the whole body, the same state is reachable over HTTPS. There, the completion of the final write is reported one event-loop turn later, and the response can be parsed in that gap. On v26.11.0+ this happens in normal use because of #XXXXX. With 22 concurrent 8 MiB `PUT`s over one keep-alive HTTPS agent and the client pinned to one CPU, 6 of 110 requests hung on v26.13.1.\n\n\n### What is the expected behavior? Why is that the expected behavior?\n\n```\nnode v26.13.1 fix=false: writableFinished=true writableNeedDrain=false\n```\n\nA request that is still writing its body should keep receiving `'drain'` from its socket until it has ended, whether or not the response has already arrived. Otherwise any writer that honors backpressure, including `stream.pipe(req)`, can never finish the request.\n\n\n### What do you see instead?\n\n```\nnode v26.13.1 fix=false: writableFinished=false writableNeedDrain=true\n```\n\nThe request never finishes, `writableNeedDrain` stays `true`, and the socket stays in flight, which keeps the process alive.\n\n\n### Additional information\n\nIn `lib/_http_client.js`, `socketOnData()` calls `socket.removeListener('drain', ondrain)` as soon as `parser.incoming.complete` is set, without checking whether the request still has `kNeedDrain` set. `responseOnEnd()` does not release the socket in this state, because `req.writableFinished` is `false`, so the socket stays referenced indefinitely.\n\nI have a patch, with a test, that keeps `ondrain` attached until the request has ended and removes it in `responseKeepAlive()`. I can open a PR.\n\n## AI Disclaimer\n\nThis report was made almost entirely with an AI. With the exception of this precise disclaimer.\nIn particular, this was a bug I found in production for our local infrastructure, where CI runs in a self-hosted Forgejo, and a Forgejo Runner, suddenly hung when using forgejo/upload-artifacts@v4 and @v5 with a ~200MB artifact, despite everything working with @v3, and in earlier versions of node.\n\nFor now we are reverting to @v3, but I am obviously notifying the maintainers of the forgejo runner so this can be worked around upstream.\n\nThe AI agent has made a patch that schedules `endReadable()` in `flowSync()` under the same condition as `read()`, with a test.\n\nI don't post a PR, because the AI contribution guidelines specify that the user proposing a PR must fully understand the changes, which I don't yet fully. Thus I post the patch and other relevant files, so the maintainers can check its accuracy, and maybe implement their own patch/test if needed\n\nI am open to any other data that might be needed to clarify the situation, to the best of my ability.\n\nFound at the same time as issue #67762\n\n[0002-http-keep-forwarding-drain-after-response-completes.patch](https://github.com/user-attachments/files/35374205/0002-http-keep-forwarding-drain-after-response-completes.patch)","author":{"url":"https://github.com/AZMCode","@type":"Person","name":"AZMCode"},"datePublished":"2026-11-24T20:34:52Z","url":"https://github.com/nodejs/node/issues/67763"}
| 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:aec5bd10-5f6f-3919-91c3-b58087861d95 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD06:30F58B:3CDEBF:4FF191:6B0619A1 |
| html-safe-nonce | 5273b35783c85c130c642da5337bfbee01ff5f5d7ae3295f2833e9febedb8f7a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDA2OjMwRjU4QjozQ0RFQkY6NEZGMTkxOjZCMDYxOUExIiwidmlzaXRvcl9pZCI6IjM5NjI0MzU4NTAxMDkwNjU2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8da69e1af571b220862a8b19c326f9cef0a055e4854a5a5faa2cd121d59a6a00 |
| hovercard-subject-tag | issue:6590885653 |
| 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/67763/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7737d83f4406c327a235153a0e0e0928aecf2a35cd7713bb90a8e2931e78dd2a/nodejs/node/issues/67763 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7737d83f4406c327a235153a0e0e0928aecf2a35cd7713bb90a8e2931e78dd2a/nodejs/node/issues/67763 |
| og:image:alt | Version v20.20.2, v22.23.5, v24.22.3, v26.13.1 (all tested versions) Platform Linux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_6... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AZMCode |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| 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 | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| 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