René's URL Explorer Experiment


Title: http: 'drain' is never emitted for chunked responses with multi-byte strings (v24.22.0 regression) · Issue #66781 · nodejs/node · GitHub

Open Graph Title: http: 'drain' is never emitted for chunked responses with multi-byte strings (v24.22.0 regression) · Issue #66781 · nodejs/node

X Title: http: 'drain' is never emitted for chunked responses with multi-byte strings (v24.22.0 regression) · Issue #66781 · nodejs/node

Description: Version v24.22.0 (also main / v27.0.0-pre; v24.21.0 is not affected) Platform Darwin arm64 (macOS); also linux x64 in Docker (node:24-alpine) Subsystem http What steps will reproduce the bug? Run the following single-file script with nod...

Open Graph Description: Version v24.22.0 (also main / v27.0.0-pre; v24.21.0 is not affected) Platform Darwin arm64 (macOS); also linux x64 in Docker (node:24-alpine) Subsystem http What steps will reproduce the bug? Run t...

X Description: Version v24.22.0 (also main / v27.0.0-pre; v24.21.0 is not affected) Platform Darwin arm64 (macOS); also linux x64 in Docker (node:24-alpine) Subsystem http What steps will reproduce the bug? Run t...

Opengraph URL: https://github.com/nodejs/node/issues/66781

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"http: 'drain' is never emitted for chunked responses with multi-byte strings (v24.22.0 regression)","articleBody":"### Version\n\nv24.22.0 (also main / v27.0.0-pre; v24.21.0 is not affected)\n\n### Platform\n\n```text\nDarwin arm64 (macOS); also linux x64 in Docker (node:24-alpine)\n```\n\n### Subsystem\n\nhttp\n\n### What steps will reproduce the bug?\n\nRun the following single-file script with `node repro.js`. It starts an HTTP server that writes 30k multi-byte string chunks to a chunked `http.ServerResponse`, awaiting `'drain'` whenever `write()` returns `false`. A forked child process reads the response slowly.\n\n```js\n'use strict';\nconst http = require('node:http');\nconst { once } = require('node:events');\nconst { fork } = require('node:child_process');\n\nif (process.argv[2] === 'client') {\n  // Slow consumer in a separate process.\n  http.get(`http://127.0.0.1:${process.argv[3]}/`, (res) => {\n    let bytes = 0;\n    res.on('data', (chunk) => {\n      bytes += chunk.length;\n      const t = performance.now();\n      while (performance.now() - t \u003c 2); // simulate per-chunk work\n    });\n    res.on('end', () => process.send({ done: true, bytes }));\n  });\n  return;\n}\n\nconst ROWS = 30000;\n// Rows of mixed ASCII + 2-byte UTF-8 characters, ~200-600 bytes each.\nconst rows = Array.from({ length: ROWS }, (_, i) =>\n  'a'.repeat(50 + (i * 37) % 200) + 'ع'.repeat(50 + (i * 53) % 150) + '\\n');\n\nconst server = http.createServer(async (req, res) => {\n  for (let i = 0; i \u003c ROWS; i++) {\n    if (!res.write(rows[i])) {\n      const timer = setTimeout(() => {\n        console.log(`${process.version}: STALLED at row ${i}`, {\n          writableNeedDrain: res.writableNeedDrain,\n          writableLength: res.writableLength,\n          socketWritableLength: res.socket.writableLength,\n          socketWritableNeedDrain: res.socket.writableNeedDrain,\n        });\n        process.exit(1);\n      }, 3000);\n      await once(res, 'drain');\n      clearTimeout(timer);\n    }\n  }\n  res.end();\n});\n\nserver.listen(0, () => {\n  const child = fork(__filename, ['client', server.address().port]);\n  child.on('message', ({ bytes }) => {\n    console.log(`${process.version}: OK, client received ${bytes} bytes`);\n    child.kill();\n    process.exit(0);\n  });\n});\n```\n\n### How often does it reproduce? Is there a required condition?\n\nEvery time in our environment (it stalls at the same row on every run).\n\nRequired conditions:\n- a chunked response (no `Content-Length`)\n- **multi-byte string chunks**: the same script with ASCII-only rows of identical *byte* length does not stall\n- a reader slow enough to apply backpressure (a fast reader such as `curl` does not trigger it)\n\n### What is the expected behavior? Why is that the expected behavior?\n\nAfter `res.write()` returns `false`, `'drain'` is emitted once the buffered data has been flushed, as documented for writable streams. v24.21.0 completes:\n\n```\nv24.21.0: OK, client received 11985000 bytes\n```\n\n### What do you see instead?\n\n`'drain'` is never emitted, even though nothing is buffered anymore:\n\n```\nv24.22.0: STALLED at row 2140 {\n  writableNeedDrain: true,\n  writableLength: 0,\n  socketWritableLength: 0,\n  socketWritableNeedDrain: false\n}\n```\n\nThe writer waits forever. In production the client (undici) eventually aborts with `UND_ERR_BODY_TIMEOUT` after 300 s.\n\n### Additional information\n\n- This started with v24.22.0, which includes #64987 (`http: coalesce chunked writes during auto-corking`). With that change, `write()` decides its return value from the message-level buffer (`msg.writableLength`), where `kChunkedLength` is measured in **bytes** (`Buffer.byteLength`). Once that reaches the high-water mark it returns `false` and sets `kNeedDrain`.\n- The coalesced chunks are then flushed in the next-tick `uncork()` via `socket.write()` with string data, and `net.Socket` accounts string chunks in **UTF-16 code units**, not bytes:\n\n  ```js\n  socket.cork(); socket.write('ع'.repeat(1000)); // 2000 bytes on the wire\n  socket.writableLength; // 1000 (same on v24.21.0 and v24.22.0)\n  ```\n\n  So with multi-byte text the socket believes it is below its high-water mark, `socket.write()` returns `true`, the socket never sets `needDrain` and never emits `'drain'`. The other emit path (`uncork()` checking `writableLength === 0` right after the flush) is missed because bytes are still pending at that instant. `kNeedDrain` stays `true` with nothing buffered.\n- Before #64987 the return value came from the socket itself, so the two accountings could not disagree. With ASCII-only data bytes equal code units, which is why only multi-byte bodies are affected.\n- #66039 (`http: count buffered outgoing data in bytes`) looks related but does not cover this: it changes the buffered branch of `_writeRaw()` (`outputData` / `outputSize`), and instrumenting this repro shows that branch is never taken (every write goes straight to the socket).\n- I have a fix with a test that re-checks the drain condition once the flushed data has been written, and will open a PR referencing this issue.","author":{"url":"https://github.com/junyup0503","@type":"Person","name":"junyup0503"},"datePublished":"2026-10-16T06:11:16Z","url":"https://github.com/nodejs/node/issues/66781"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e0e46dfe-6777-40f0-8565-d593e86b0432
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA792:F5278:765900:9CDCE3:6AED2344
html-safe-nonce70484e06bce7160fb61d92d582785b9e977b493a862963ff9e685802c51320a4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzkyOkY1Mjc4Ojc2NTkwMDo5Q0RDRTM6NkFFRDIzNDQiLCJ2aXNpdG9yX2lkIjoiNTY4MTM2MjEwNzkxOTgzNTk3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9e9bb455822b2e7f51df5901d7045644079f1216cc029c5a93d5c89fcf03d1ed
hovercard-subject-tagissue:5879299858
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/66781/issue_layout
twitter:imagehttps://opengraph.githubassets.com/372567ba60c59b20b5e07275dfe9d3d7367c33179684209fe50e349b0e0f8ba5/nodejs/node/issues/66781
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/372567ba60c59b20b5e07275dfe9d3d7367c33179684209fe50e349b0e0f8ba5/nodejs/node/issues/66781
og:image:altVersion v24.22.0 (also main / v27.0.0-pre; v24.21.0 is not affected) Platform Darwin arm64 (macOS); also linux x64 in Docker (node:24-alpine) Subsystem http What steps will reproduce the bug? Run t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejunyup0503
hostnamegithub.com
expected-hostnamegithub.com
Nonee3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release707a24b346ac8a82878b9c084efaa38a997660cb
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/66781#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F66781
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F66781
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/66781
Reloadhttps://github.com/nodejs/node/issues/66781
Reloadhttps://github.com/nodejs/node/issues/66781
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues657 (657)https://github.com/nodejs/node/issues
Pull requests666 (666)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/66781
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/66781
#66782https://github.com/nodejs/node/pull/66782
http: 'drain' is never emitted for chunked responses with multi-byte strings (v24.22.0 regression)https://github.com/nodejs/node/issues/66781#top
#66782https://github.com/nodejs/node/pull/66782
https://github.com/junyup0503
junyup0503https://github.com/junyup0503
on Oct 16, 2026https://github.com/nodejs/node/issues/66781#issue-5879299858
http: coalesce chunked writes during auto-corking #64987https://github.com/nodejs/node/pull/64987
http: coalesce chunked writes during auto-corking #64987https://github.com/nodejs/node/pull/64987
http: count buffered outgoing data in bytes #66039https://github.com/nodejs/node/pull/66039
https://github.com/par333k
par333khttps://github.com/par333k
on Oct 16, 2026https://github.com/nodejs/node/issues/66781#issuecomment-6209381706
junyup0503https://github.com/junyup0503
on Oct 16, 2026https://github.com/nodejs/node/issues/66781#event-33418926086
http: emit 'drain' after flushing coalesced chunkshttps://github.com/junyup0503/node/commit/a3602435ae0ed6a5eea049c965f21e2ce0818aa5
a360243https://github.com/junyup0503/node/commit/a3602435ae0ed6a5eea049c965f21e2ce0818aa5
https://github.com/imrihe-ledge
imrihe-ledgehttps://github.com/imrihe-ledge
on Oct 22, 2026https://github.com/nodejs/node/issues/66781#issuecomment-6339112212
#66782https://github.com/nodejs/node/pull/66782
#66924https://github.com/nodejs/node/issues/66924
#66782https://github.com/nodejs/node/pull/66782
https://github.com/imrihe-ledge
imrihe-ledgehttps://github.com/imrihe-ledge
on Oct 22, 2026https://github.com/nodejs/node/issues/66781#issuecomment-6339243373
pjsteinhttps://github.com/pjstein
on Oct 23, 2026https://github.com/nodejs/node/issues/66781#event-34075239143
Bun, erlang certifi and CPython fixes; four test hosts; engines range…https://github.com/pjstein/fumigator/commit/cfded8fadbfd04e00a9a14effae3f9639103e18e
cfded8fhttps://github.com/pjstein/fumigator/commit/cfded8fadbfd04e00a9a14effae3f9639103e18e
absorbbhttps://github.com/absorbb
on Oct 28, 2026https://github.com/nodejs/node/issues/66781#event-34463856448
JITSU-269: fix ClickHouse upload stalls and lock rotor runtime depend…https://github.com/jitsucom/jitsu/commit/33e09cf9f041899474f8cda9170d029f764cbc29
33e09cfhttps://github.com/jitsucom/jitsu/commit/33e09cf9f041899474f8cda9170d029f764cbc29
https://github.com/H4ad
H4adhttps://github.com/H4ad
on Oct 31, 2026https://github.com/nodejs/node/issues/66781#issuecomment-6547431500
H4ad/serverless-adapter#423 (comment)https://github.com/H4ad/serverless-adapter/issues/423#issue-6125965220
#66782https://github.com/nodejs/node/pull/66782
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/66781
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/66781
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.