René's URL Explorer Experiment


Title: `stream.pipeline()` leaks file descriptors when it throws synchronously (ERR_STREAM_UNABLE_TO_PIPE) · Issue #65063 · nodejs/node · GitHub

Open Graph Title: `stream.pipeline()` leaks file descriptors when it throws synchronously (ERR_STREAM_UNABLE_TO_PIPE) · Issue #65063 · nodejs/node

X Title: `stream.pipeline()` leaks file descriptors when it throws synchronously (ERR_STREAM_UNABLE_TO_PIPE) · Issue #65063 · nodejs/node

Description: Version v24.11.1, and main (735a09f999a) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? stream.pipeline() wires the streams together in a loop, and that l...

Open Graph Description: Version v24.11.1, and main (735a09f999a) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? stream.pipeline() wires th...

X Description: Version v24.11.1, and main (735a09f999a) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? stream.pipeline() wires th...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`stream.pipeline()` leaks file descriptors when it throws synchronously (ERR_STREAM_UNABLE_TO_PIPE)","articleBody":"### Version\n\nv24.11.1, and `main` (`735a09f999a`)\n\n### Platform\n\nReproduced on Windows 11 x64; the code path is platform independent.\n\n### Subsystem\n\nstream\n\n### What steps will reproduce the bug?\n\n`stream.pipeline()` wires the streams together in a loop, and that loop can throw synchronously. The most common case is `ERR_STREAM_UNABLE_TO_PIPE`, raised when the destination is already closed or destroyed. When it throws, every stream `pipeline()` had already taken ownership of is left undestroyed, so its resources leak. For a `fs.ReadStream` source that means a leaked file descriptor.\n\nThe trigger is an ordinary production condition: piping to a destination that has already gone away, e.g. `pipeline(fs.createReadStream(file), res)` after the HTTP client disconnected.\n\n```js\nimport { pipeline, PassThrough, Writable } from 'node:stream';\nimport { pipeline as pipelinePromise } from 'node:stream/promises';\nimport { once, getEventListeners } from 'node:events';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nconst tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pipeline-leak-'));\nconst file = path.join(tmp, 'data.bin');\nfs.writeFileSync(file, Buffer.alloc(4096, 'x'));\n\nconst openStream = async () => {\n  const rs = fs.createReadStream(file);\n  await once(rs, 'open');          // ensure the fd is really allocated\n  return rs;\n};\nconst deadWritable = () => {\n  const w = new Writable({ write(c, e, cb) { cb(); } });\n  w.destroy();                     // destination already gone\n  return w;\n};\n\n// 1. callback form\n{\n  const sources = [];\n  for (let i = 0; i \u003c 50; i++) {\n    const rs = await openStream();\n    sources.push(rs);\n    try {\n      pipeline(rs, new PassThrough(), deadWritable(), () => {});\n    } catch (err) {\n      if (i === 0) console.log('callback form throws :', err.code);\n    }\n  }\n  await new Promise((r) => setTimeout(r, 150));\n  console.log('  sources undestroyed :', sources.filter((s) => !s.destroyed).length, '/ 50  (expected 0)');\n  console.log('  fds still open      :', sources.filter((s) => s.fd != null).length, '/ 50  (expected 0)');\n  for (const s of sources) s.destroy();\n}\n\n// 2. promise form, plus the caller's AbortSignal\n{\n  const ac = new AbortController();  // long-lived, e.g. a server shutdown signal\n  const sources = [];\n  for (let i = 0; i \u003c 50; i++) {\n    const rs = await openStream();\n    sources.push(rs);\n    try {\n      await pipelinePromise(rs, new PassThrough(), deadWritable(), { signal: ac.signal });\n    } catch (err) {\n      if (i === 0) console.log('promise form rejects :', err.code);\n    }\n  }\n  await new Promise((r) => setTimeout(r, 150));\n  console.log('  sources undestroyed :', sources.filter((s) => !s.destroyed).length, '/ 50  (expected 0)');\n  console.log('  fds still open      :', sources.filter((s) => s.fd != null).length, '/ 50  (expected 0)');\n  console.log('  abort listeners     :', getEventListeners(ac.signal, 'abort').length, '/ 50  (expected 0)');\n  for (const s of sources) s.destroy();\n}\n\n// 3. control: an ordinary asynchronous failure does clean up correctly\n{\n  const rs = fs.createReadStream(path.join(tmp, 'nope'));\n  const mid = new PassThrough();\n  await new Promise((resolve) => pipeline(rs, mid, new PassThrough(), () => resolve()));\n  console.log('control (ENOENT)     : rs.destroyed =', rs.destroyed, '| mid.destroyed =', mid.destroyed, ' (both expected true)');\n}\n\nfs.rmSync(tmp, { recursive: true, force: true });\n```\n\n### How often does it reproduce? Is there a required condition?\n\nEvery time. The only condition is that `pipeline()` throws while wiring the streams up, after at least one stream has already been wired.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nAll the streams should be destroyed and the file descriptors released, and the listener added to the caller's `AbortSignal` should be removed.\n\n`doc/api/stream.md` states:\n\n> `stream.pipeline()` closes all the streams when an error is raised.\n\nand\n\n> `stream.pipeline()` will call `stream.destroy(err)` on all streams except: `Readable` streams which have emitted `'end'` or `'close'`; `Writable` streams which have emitted `'finish'` or `'close'`.\n\nThe sources here emitted none of those events. The control case in the reproduction shows that an *asynchronous* pipeline error does destroy everything, so the two paths disagree.\n\n### What do you see instead?\n\n```\ncallback form throws : ERR_STREAM_UNABLE_TO_PIPE\n  sources undestroyed : 50 / 50  (expected 0)\n  fds still open      : 50 / 50  (expected 0)\npromise form rejects : ERR_STREAM_UNABLE_TO_PIPE\n  sources undestroyed : 50 / 50  (expected 0)\n  fds still open      : 50 / 50  (expected 0)\n  abort listeners     : 50 / 50  (expected 0)\ncontrol (ENOENT)     : rs.destroyed = true | mid.destroyed = true  (both expected true)\n```\n\n### Additional information\n\nThe wiring loop in `pipelineImpl()` ([`lib/internal/streams/pipeline.js`](https://github.com/nodejs/node/blob/main/lib/internal/streams/pipeline.js)) pushes a destroy function into `destroys` for each stream it adopts, and `finishImpl()` is the only code that drains `destroys`, disposes the `AbortSignal` listener and calls `ac.abort()`.\n\nThe loop is not wrapped in `try`/`finally`, and it can throw at six places:\n\n* `ERR_STREAM_UNABLE_TO_PIPE` when the next stream is already closed or destroyed\n* `ERR_INVALID_RETURN_VALUE` (x3) when a transform function returns something that is not iterable\n* `ERR_INVALID_ARG_TYPE` (x2) when a value cannot be piped into the next stream\n\nWhen any of these fire, `finishImpl()` never runs, so nothing in `destroys` is ever called.\n\nThe `ERR_INVALID_RETURN_VALUE` path leaks in exactly the same way:\n\n```js\nconst source = fs.createReadStream(file);\npipeline(source, () => 42, new PassThrough(), () => {});  // throws\n// source is left open\n```\n\nI have a fix and will open a PR shortly.\n","author":{"url":"https://github.com/shani-singh1","@type":"Person","name":"shani-singh1"},"datePublished":"2026-08-06T01:48:01Z","url":"https://github.com/nodejs/node/issues/65063"}

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:efa5b586-3fe3-7834-7d72-5ef5320a688a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8B9A:2FF8F1:E6E51B:12D4E07:6AED5644
html-safe-nonce34dfe8ac0491d3571d31460fe0f41c4932fa5d97d4739838da8f1b9537237f64
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjlBOjJGRjhGMTpFNkU1MUI6MTJENEUwNzo2QUVENTY0NCIsInZpc2l0b3JfaWQiOiIzOTgyMDk1OTExNTQ2NjA5MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5ae2153db86723246e97d2b50a1bb61927acb87642fe1b68cbf9086fea94b5c6
hovercard-subject-tagissue:5076780702
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/65063/issue_layout
twitter:imagehttps://opengraph.githubassets.com/eacf2c0c0123d971a49c149c5be4f1f065d8794abb908b71d0559b94e763ea7a/nodejs/node/issues/65063
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/eacf2c0c0123d971a49c149c5be4f1f065d8794abb908b71d0559b94e763ea7a/nodejs/node/issues/65063
og:image:altVersion v24.11.1, and main (735a09f999a) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? stream.pipeline() wires th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameshani-singh1
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
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
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/65063#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F65063
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%2F65063
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/65063
Reloadhttps://github.com/nodejs/node/issues/65063
Reloadhttps://github.com/nodejs/node/issues/65063
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues654 (654)https://github.com/nodejs/node/issues
Pull requests662 (662)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/65063
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/65063
#65064https://github.com/nodejs/node/pull/65064
stream.pipeline() leaks file descriptors when it throws synchronously (ERR_STREAM_UNABLE_TO_PIPE)https://github.com/nodejs/node/issues/65063#top
#65064https://github.com/nodejs/node/pull/65064
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
https://github.com/shani-singh1
shani-singh1https://github.com/shani-singh1
on Aug 6, 2026https://github.com/nodejs/node/issues/65063#issue-5076780702
lib/internal/streams/pipeline.jshttps://github.com/nodejs/node/blob/main/lib/internal/streams/pipeline.js
shani-singh1https://github.com/shani-singh1
on Aug 6, 2026https://github.com/nodejs/node/issues/65063#event-29064415998
stream: clean up when pipeline throws synchronouslyhttps://github.com/shani-singh1/node/commit/cb6d8990110e9509350e27dd568dea1d4a3b2e93
cb6d899https://github.com/shani-singh1/node/commit/cb6d8990110e9509350e27dd568dea1d4a3b2e93
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Nov 5, 2026https://github.com/nodejs/node/issues/65063#issuecomment-6646834925
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 Nov 5, 2026https://github.com/nodejs/node/issues/65063#event-35192637534
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/65063
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/65063
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
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.