René's URL Explorer Experiment


Title: Readable.toWeb(): uncaughtException (ERR_INVALID_STATE "Controller is already closed") when the stream is canceled during backpressure resume · Issue #64529 · nodejs/node · GitHub

Open Graph Title: Readable.toWeb(): uncaughtException (ERR_INVALID_STATE "Controller is already closed") when the stream is canceled during backpressure resume · Issue #64529 · nodejs/node

X Title: Readable.toWeb(): uncaughtException (ERR_INVALID_STATE "Controller is already closed") when the stream is canceled during backpressure resume · Issue #64529 · nodejs/node

Description: Version v22.23.1 (also affects main — the unguarded code is still present) Platform Linux (Docker, x86_64) — also reproduced on Darwin 25.5.0 arm64 Subsystem stream, webstreams What steps will reproduce the bug? Convert a Node Readable (...

Open Graph Description: Version v22.23.1 (also affects main — the unguarded code is still present) Platform Linux (Docker, x86_64) — also reproduced on Darwin 25.5.0 arm64 Subsystem stream, webstreams What steps will repr...

X Description: Version v22.23.1 (also affects main — the unguarded code is still present) Platform Linux (Docker, x86_64) — also reproduced on Darwin 25.5.0 arm64 Subsystem stream, webstreams What steps will repr...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Readable.toWeb(): uncaughtException (ERR_INVALID_STATE \"Controller is already closed\") when the stream is canceled during backpressure resume","articleBody":"### Version\n\nv22.23.1 (also affects `main` — the unguarded code is still present)\n\n### Platform\n\n```text\nLinux (Docker, x86_64) — also reproduced on Darwin 25.5.0 arm64\n```\n\n### Subsystem\n\nstream, webstreams\n\n### What steps will reproduce the bug?\n\nConvert a Node `Readable` (e.g. a `PassThrough`) to a web `ReadableStream` with `Readable.toWeb()`, pipe it to a slow sink so backpressure pause/resume cycles occur, and cancel/abort mid-transfer (as happens whenever an HTTP client disconnects while a server streams a response built from `new Response(Readable.toWeb(nodeStream))`):\n\n```js\n// repro.mjs — node repro.mjs\nimport { PassThrough, Readable, pipeline as pump } from \"node:stream\";\n\nlet uncaught = 0;\nprocess.on(\"uncaughtExceptionMonitor\", (e) => { if (++uncaught === 1) console.log(e.stack); });\nprocess.on(\"uncaughtException\", () => {});\n\nasync function one() {\n  const src = new Readable({\n    read() {\n      this.push(Buffer.alloc(16 * 1024, 1));\n      if ((this.bytes = (this.bytes || 0) + 16384) > 512 * 1024) this.push(null);\n    },\n  });\n  const pt = new PassThrough({ highWaterMark: 16384 });\n  pump(src, pt, () => {});\n  const web = Readable.toWeb(pt);\n\n  const ac = new AbortController();\n  const writer = new WritableStream(\n    { async write() { await new Promise((r) => setTimeout(r, 1)); } },  // slow sink → backpressure\n    { highWaterMark: 1 },\n  );\n  setTimeout(() => ac.abort(), Math.floor(Math.random() * 12));          // client disconnect\n  try { await web.pipeTo(writer, { signal: ac.signal }); } catch {}\n  await new Promise((r) => setImmediate(r));\n}\n\nfor (let i = 0; i \u003c 400; i++) await one();\nconsole.log(`uncaught=${uncaught}/400 node=${process.version}`);\n```\n\n### How often does it reproduce? Is there a required condition?\n\n400/400 iterations on v22.23.1 with the harness above. Required conditions: the source is flowing under backpressure (pause → `pull()` → `resume()` cycles) and the web stream is canceled (directly or via `pipeTo` abort) while a resume tick is already scheduled.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nCanceling a `ReadableStream` produced by `Readable.toWeb()` should tear the pipeline down quietly. A consumer abort is a normal event; it should never escalate to an `uncaughtException` the user cannot catch.\n\n### What do you see instead?\n\n```\nTypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed\n    at ReadableStreamDefaultController.enqueue (node:internal/webstreams/readablestream:1077:13)\n    at PassThrough.onData (node:internal/webstreams/adapters:468:16)\n    at PassThrough.emit (node:events:519:28)\n    at Readable.read (node:internal/streams/readable:782:10)\n    at flow (node:internal/streams/readable:1283:53)\n    at resume_ (node:internal/streams/readable:1262:3)\n    at process.processTicksAndRejections (node:internal/process/task_queues:89:21)\n```\n\nThe throw happens synchronously inside an EventEmitter `'data'` callback, so it surfaces as an **uncaughtException** — unreachable by any user-level try/catch.\n\n### Additional information\n\nRoot cause in `lib/internal/webstreams/adapters.js` (`newReadableStreamFromStreamReadable`):\n\n```js\nfunction onData(chunk) {\n  // Copy the Buffer to detach it from the pool.\n  if (Buffer.isBuffer(chunk) && !objectMode)\n    chunk = new Uint8Array(chunk);\n  controller.enqueue(chunk);        // ← no closed/canceled guard\n  if (controller.desiredSize \u003c= 0)\n    streamReadable.pause();\n}\n```\n\nPer spec, `ReadableStreamCancel` sets the stream state to `\"closed\"` **before** invoking the underlying source's `cancel()` (which destroys the Node stream), and the `'data'` listener is never removed on cancel. A `resume_`-scheduled flow tick can therefore deliver one more `'data'` event after the controller is closed but before `destroy()` takes effect, and `enqueue` throws.\n\nSuggested fix: guard `onData` with `wasCanceled` (and/or wrap the `enqueue` in try/catch → destroy the source), or remove the `'data'` listener in `cancel()`.\n\nReal-world impact: any server doing `new Response(Readable.toWeb(nodeStream))` (e.g. a Next.js route handler proxying object-storage bytes) hits this whenever a browser aborts mid-download — `\u003cvideo>` seek/probe aborts made this fire on every deploy cutover for us. Note the same unguarded pattern is reachable from Next.js's own `action-handler.ts` (`Readable.toWeb(sizeLimitedBody)`).\n\nWorkaround: use pull-based `ReadableStream.from(nodeReadable)` instead of `Readable.toWeb()` — 0/400 with the same harness, and cancel still propagates destroy to the source via the async iterator's `return()`.\n","author":{"url":"https://github.com/moonjiho-bigtablet","@type":"Person","name":"moonjiho-bigtablet"},"datePublished":"2026-07-16T04:21:42Z","url":"https://github.com/nodejs/node/issues/64529"}

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:84975b38-3dc7-0ea1-1b43-96580fb69661
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE54:1085A1:621431:7EC576:6AED2AC7
html-safe-nonce567e9bc45aecedc2ad837eff4f91b950302350dbec19d54efbab9ec9a957c260
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTU0OjEwODVBMTo2MjE0MzE6N0VDNTc2OjZBRUQyQUM3IiwidmlzaXRvcl9pZCI6Ijc3MTc0NTA2ODUyNjY4NjQ4MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac39262329c5dbdbeab66b22fdbfbd63e049d612778a3c6d13a379e38a2c173115
hovercard-subject-tagissue:4898658389
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/64529/issue_layout
twitter:imagehttps://opengraph.githubassets.com/73ddc3fb960d0994501e8e16896f6097efb5cc7a04878f801ddd8390628cf9b8/nodejs/node/issues/64529
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/73ddc3fb960d0994501e8e16896f6097efb5cc7a04878f801ddd8390628cf9b8/nodejs/node/issues/64529
og:image:altVersion v22.23.1 (also affects main — the unguarded code is still present) Platform Linux (Docker, x86_64) — also reproduced on Darwin 25.5.0 arm64 Subsystem stream, webstreams What steps will repr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemoonjiho-bigtablet
hostnamegithub.com
expected-hostnamegithub.com
None9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2
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
release98b41fa4b5635ceb45a4c54320fced73817ff290
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/64529#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F64529
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%2F64529
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/64529
Reloadhttps://github.com/nodejs/node/issues/64529
Reloadhttps://github.com/nodejs/node/issues/64529
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues656 (656)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/64529
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/64529
#64766https://github.com/nodejs/node/pull/64766
Readable.toWeb(): uncaughtException (ERR_INVALID_STATE "Controller is already closed") when the stream is canceled during backpressure resumehttps://github.com/nodejs/node/issues/64529#top
#64766https://github.com/nodejs/node/pull/64766
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
web streamsIssues and PRs related to the Web Streams API.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22web%20streams%22
https://github.com/moonjiho-bigtablet
moonjiho-bigtablethttps://github.com/moonjiho-bigtablet
on Jul 16, 2026https://github.com/nodejs/node/issues/64529#issue-4898658389
https://github.com/dushyant-hada-90
dushyant-hada-90https://github.com/dushyant-hada-90
on Jul 16, 2026https://github.com/nodejs/node/issues/64529#issuecomment-4992027154
#62773https://github.com/nodejs/node/pull/62773
efekrsklhttps://github.com/efekrskl
web streamsIssues and PRs related to the Web Streams API.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22web%20streams%22
on Jul 17, 2026https://github.com/nodejs/node/issues/64529#event-28125912107
LinyaVThttps://github.com/LinyaVT
on Aug 11, 2026https://github.com/nodejs/node/issues/64529#event-29287779327
Add safe node->web stream converterhttps://github.com/LinyaVT/LinyaShare/commit/2a866f01a51c77b194ed53bb85abcc738de9a7ba
2a866f0https://github.com/LinyaVT/LinyaShare/commit/2a866f01a51c77b194ed53bb85abcc738de9a7ba
NIda2645https://github.com/NIda2645
on Aug 25, 2026https://github.com/nodejs/node/issues/64529#event-29961148719
fix: stop handing node streams to undici in nomi-localhttps://github.com/NIda2645/Nomi/commit/e5341929229800f7b1ecd4a132999203c997c60f
e534192https://github.com/NIda2645/Nomi/commit/e5341929229800f7b1ecd4a132999203c997c60f
docs(plan): 回填 undici 上游 issue 链接 + 查重与补丁验证记录https://github.com/NIda2645/Nomi/commit/732d84cd3b08261791a4b78fe9f0a0fe4367a071
732d84chttps://github.com/NIda2645/Nomi/commit/732d84cd3b08261791a4b78fe9f0a0fe4367a071
mohammedzamakhanhttps://github.com/mohammedzamakhan
on Sep 16, 2026https://github.com/nodejs/node/issues/64529#event-31221504493
fix(media): stop client aborts from killing the server, address revie…https://github.com/mohammedzamakhan/epic-startup/commit/e2ef56763bf0d15c045b9868dc9be2c7edfa94ff
e2ef567https://github.com/mohammedzamakhan/epic-startup/commit/e2ef56763bf0d15c045b9868dc9be2c7edfa94ff
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Oct 16, 2026https://github.com/nodejs/node/issues/64529#issuecomment-6205873545
GitHub Actionshttps://help.github.com/en/actions
github-actionshttps://github.com/apps/github-actions
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
on Oct 16, 2026https://github.com/nodejs/node/issues/64529#event-33396074234
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/64529
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/64529
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
web streamsIssues and PRs related to the Web Streams API.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22web%20streams%22
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.