René's URL Explorer Experiment


Title: Close listener leak in fs/promises `createReadStream` · Issue #64214 · nodejs/node · GitHub

Open Graph Title: Close listener leak in fs/promises `createReadStream` · Issue #64214 · nodejs/node

X Title: Close listener leak in fs/promises `createReadStream` · Issue #64214 · nodejs/node

Description: Version v24.18.0 Platform Darwin *.local 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:19:12 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6041 arm64 Subsystem fs/promises What steps will reproduce the bug? Here is a silly...

Open Graph Description: Version v24.18.0 Platform Darwin *.local 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:19:12 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6041 arm64 Subsystem fs/promises What steps...

X Description: Version v24.18.0 Platform Darwin *.local 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:19:12 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6041 arm64 Subsystem fs/promises What steps...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Close listener leak in fs/promises `createReadStream`","articleBody":"### Version\n\nv24.18.0\n\n### Platform\n\n```text\nDarwin *.local 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:19:12 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6041 arm64\n```\n\n### Subsystem\n\nfs/promises\n\n### What steps will reproduce the bug?\n\nHere is a silly example which prints the first 11 bytes of a file by reading them separately from disk:\n\n```js\nimport { buffer } from 'node:stream/consumers';\nimport { open } from 'node:fs/promises';\n\nconst f = await open('my-file.txt');\nfor (let i = 0; i \u003c 11; i++) {\n  const byte = await buffer(f.createReadStream({ start: i, end: i, autoClose: false }));\n  console.log(`byte ${i} is ${byte[0]}. Close listeners = ${f.listeners('close').length}`);\n}\n```\n\nRunning it (pointing at any file containing at least 11 bytes) will demonstrate the issue (output below)\n\n### How often does it reproduce? Is there a required condition?\n\nEvery call to `createReadStream` [adds a close listener to the file handle](https://github.com/nodejs/node/blob/f2f241a40ffca9ec72a103842a5e52c0c4f52767/lib/internal/fs/streams.js#L155), and I have not found a way to remove this listener. If called at least 11 times, it will trigger Node.js' built-in event leak detection warning. The threshold can be increased to avoid this warning, but the leak remains.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nOnce a stream is consumed, the [`close` event listener it attaches to the `FileHandle`](https://github.com/nodejs/node/blob/f2f241a40ffca9ec72a103842a5e52c0c4f52767/lib/internal/fs/streams.js#L155) should be removed, even when `autoClose` is false, so that applications can read arbitrarily many ranges from a file.\n\n### What do you see instead?\n\n> ```\n> byte 0 is 0. Close listeners = 1\n> byte 1 is 0. Close listeners = 2\n> byte 2 is 0. Close listeners = 3\n> byte 3 is 0. Close listeners = 4\n> byte 4 is 0. Close listeners = 5\n> byte 5 is 0. Close listeners = 6\n> byte 6 is 0. Close listeners = 7\n> byte 7 is 0. Close listeners = 8\n> byte 8 is 0. Close listeners = 9\n> byte 9 is 0. Close listeners = 10\n> (node:70360) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [FileHandle]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit\n>     at genericNodeError (node:internal/errors:985:15)\n>     at wrappedFn (node:internal/errors:539:14)\n>     at _addListener (node:events:590:17)\n>     at FileHandle.addListener (node:events:608:10)\n>     at importFd (node:internal/fs/streams:156:16)\n>     at new ReadStream (node:internal/fs/streams:189:30)\n>     at FileHandle.createReadStream (node:internal/fs/promises:363:12)\n>     at file:///[...]/test.mts:6:15\n>     at process.processTicksAndRejections (node:internal/process/task_queues:104:5)\n> byte 10 is 0. Close listeners = 11\n> ```\n\n### Additional information\n\nThis can be worked around in user-space with a hacky approach:\n\n```js\nfunction createSafeReadStream(handle, options) {\n  const before = handle.listeners('close').length;\n  const stream = handle.createReadStream(options);\n  const after = handle.listeners('close');\n  if (after.length > before) {\n    const listener = after[after.length - 1];\n    const teardown = () => {\n      handle.off('close', listener);\n      stream.off('end', teardown);\n      stream.off('error', teardown);\n    };\n    stream.once('end', teardown);\n    stream.once('error', teardown);\n  }\n  return stream;\n}\n\n// ...\n\nfor (let i = 0; i \u003c 11; i++) {\n  const byte = await buffer(createSafeReadStream(f, { start: i, end: i, autoClose: false }));\n  console.log(`byte ${i} is ${byte[0]}. Close listeners = ${f.listeners('close').length}`);\n}\n```","author":{"url":"https://github.com/davidje13","@type":"Person","name":"davidje13"},"datePublished":"2026-06-30T10:17:10Z","url":"https://github.com/nodejs/node/issues/64214"}

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:ccd28666-49f0-74c9-18a7-2fb1208e7ec0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA8D6:119BBD:645236:8211F7:6AED2C95
html-safe-noncec51df65e17951c06be1edc6b93502410b4903ac57fd58c86651d51f015983d67
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEQ2OjExOUJCRDo2NDUyMzY6ODIxMUY3OjZBRUQyQzk1IiwidmlzaXRvcl9pZCI6IjE2MTE2MTY5MTgzMjc2MDIzMjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac7f6e36cf5d34bee74f4a5fc6ff96e53598a2dfd1fd1ef71d5f408b985e77e476
hovercard-subject-tagissue:4775818261
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/64214/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ff736ad4c940999860c2c146824ebf0e059814644d7a1b6c19f5a645762e2f78/nodejs/node/issues/64214
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ff736ad4c940999860c2c146824ebf0e059814644d7a1b6c19f5a645762e2f78/nodejs/node/issues/64214
og:image:altVersion v24.18.0 Platform Darwin *.local 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:19:12 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6041 arm64 Subsystem fs/promises What steps...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedavidje13
hostnamegithub.com
expected-hostnamegithub.com
Nonee51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a
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
release59ebb7b901cc154ecc179a44f266fcf69f343b30
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/64214#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F64214
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%2F64214
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/64214
Reloadhttps://github.com/nodejs/node/issues/64214
Reloadhttps://github.com/nodejs/node/issues/64214
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/64214
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/64214
#64227https://github.com/nodejs/node/pull/64227
#66080https://github.com/nodejs/node/pull/66080
Close listener leak in fs/promises createReadStreamhttps://github.com/nodejs/node/issues/64214#top
#64227https://github.com/nodejs/node/pull/64227
#66080https://github.com/nodejs/node/pull/66080
fsIssues and PRs related to file-system APIs and the fs module.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22fs%22
https://github.com/davidje13
davidje13https://github.com/davidje13
on Jun 30, 2026https://github.com/nodejs/node/issues/64214#issue-4775818261
adds a close listener to the file handlehttps://github.com/nodejs/node/blob/f2f241a40ffca9ec72a103842a5e52c0c4f52767/lib/internal/fs/streams.js#L155
close event listener it attaches to the FileHandlehttps://github.com/nodejs/node/blob/f2f241a40ffca9ec72a103842a5e52c0c4f52767/lib/internal/fs/streams.js#L155
https://github.com/Paraspandey-debugs
Paraspandey-debugshttps://github.com/Paraspandey-debugs
on Jul 1, 2026https://github.com/nodejs/node/issues/64214#issuecomment-4850922682
nodejs-github-bothttps://github.com/nodejs-github-bot
on Aug 17, 2026https://github.com/nodejs/node/issues/64214#event-29582008631
fs: fix close listener leak in FileHandle streamshttps://github.com/nodejs/node/commit/8488e1324af0631105cfaf365e0e2673de295696
8488e13https://github.com/nodejs/node/commit/8488e1324af0631105cfaf365e0e2673de295696
nodejs-github-bothttps://github.com/nodejs-github-bot
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#64227https://github.com/nodejs/node/pull/64227
on Aug 17, 2026https://github.com/nodejs/node/issues/64214#event-29582008711
https://github.com/MikeMcC399
MikeMcC399https://github.com/MikeMcC399
on Aug 18, 2026https://github.com/nodejs/node/issues/64214#issuecomment-5330954273
#64227https://github.com/nodejs/node/pull/64227
#64227 (comment)https://github.com/nodejs/node/pull/64227#issuecomment-5329960591
#65387https://github.com/nodejs/node/pull/65387
#65387 (comment)https://github.com/nodejs/node/pull/65387#issuecomment-5330880926
MikeMcC399https://github.com/MikeMcC399
on Aug 18, 2026https://github.com/nodejs/node/issues/64214#event-29631599331
nodejs-github-bothttps://github.com/nodejs-github-bot
on Aug 19, 2026https://github.com/nodejs/node/issues/64214#event-29664944273
Revert "fs: fix close listener leak in FileHandle streams"https://github.com/nodejs/node/commit/882a781cfbf8846540ef6c865c4f0f19ade47cbd
882a781https://github.com/nodejs/node/commit/882a781cfbf8846540ef6c865c4f0f19ade47cbd
trivikrhttps://github.com/trivikr
fsIssues and PRs related to file-system APIs and the fs module.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22fs%22
on Aug 21, 2026https://github.com/nodejs/node/issues/64214#event-29784566057
panvahttps://github.com/panva
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 21, 2026https://github.com/nodejs/node/issues/64214#event-29786487792
https://github.com/MikeMcC399
MikeMcC399https://github.com/MikeMcC399
on Aug 21, 2026https://github.com/nodejs/node/issues/64214#issuecomment-5366291146
panvahttps://github.com/panva
on Aug 21, 2026https://github.com/nodejs/node/issues/64214#event-29788327544
https://github.com/panva
panvahttps://github.com/panva
on Aug 21, 2026https://github.com/nodejs/node/issues/64214#issuecomment-5366322961
https://github.com/davidje13
davidje13https://github.com/davidje13
on Aug 24, 2026https://github.com/nodejs/node/issues/64214#issuecomment-5400635792
@ronaghttps://github.com/ronag
your commenthttps://github.com/nodejs/node/pull/65387#issuecomment-5330880926
aduh95https://github.com/aduh95
on Aug 25, 2026https://github.com/nodejs/node/issues/64214#event-30010173009
fs: fix close listener leak in FileHandle streamshttps://github.com/nodejs/node/commit/a6271eb5c7ec6f668e6f70e3b7579fa74c393907
a6271ebhttps://github.com/nodejs/node/commit/a6271eb5c7ec6f668e6f70e3b7579fa74c393907
Revert "fs: fix close listener leak in FileHandle streams"https://github.com/nodejs/node/commit/29b63dd95e7c8f891d3367f95849c797d95dcfce
29b63ddhttps://github.com/nodejs/node/commit/29b63dd95e7c8f891d3367f95849c797d95dcfce
fs: fix close listener leak in FileHandle streamshttps://github.com/nodejs/node/commit/8873b91fce8d53e699639aab4bd686309875d14d
8873b91https://github.com/nodejs/node/commit/8873b91fce8d53e699639aab4bd686309875d14d
Revert "fs: fix close listener leak in FileHandle streams"https://github.com/nodejs/node/commit/810929b6dd853b005c1ba40ff8518ffa26129688
810929bhttps://github.com/nodejs/node/commit/810929b6dd853b005c1ba40ff8518ffa26129688
https://github.com/davidje13
davidje13https://github.com/davidje13
on Aug 26, 2026https://github.com/nodejs/node/issues/64214#issuecomment-5422024397
https://github.com/davidje13/web-listener/blob/main/src/util/createSafeReadStream.mtshttps://github.com/davidje13/web-listener/blob/main/src/util/createSafeReadStream.mts
aduh95https://github.com/aduh95
on Aug 27, 2026https://github.com/nodejs/node/issues/64214#event-30102946760
fs: fix close listener leak in FileHandle streamshttps://github.com/nodejs/node/commit/071d46d3ddf5ae576e09be7fe1c18b2b0659e56a
071d46dhttps://github.com/nodejs/node/commit/071d46d3ddf5ae576e09be7fe1c18b2b0659e56a
Revert "fs: fix close listener leak in FileHandle streams"https://github.com/nodejs/node/commit/312f15558849395d26a7d5d943779eb36a27bf1f
312f155https://github.com/nodejs/node/commit/312f15558849395d26a7d5d943779eb36a27bf1f
aduh95https://github.com/aduh95
on Sep 8, 2026https://github.com/nodejs/node/issues/64214#event-30786941567
fs: fix close listener leak in FileHandle streamshttps://github.com/nodejs/node/commit/996f63632ef3c328249e2710591cb6f3ed45fb94
996f636https://github.com/nodejs/node/commit/996f63632ef3c328249e2710591cb6f3ed45fb94
Revert "fs: fix close listener leak in FileHandle streams"https://github.com/nodejs/node/commit/42fd92677aaaeb07d27eadd0f1b5b913944333dc
42fd926https://github.com/nodejs/node/commit/42fd92677aaaeb07d27eadd0f1b5b913944333dc
rasadregmihttps://github.com/rasadregmi
on Sep 17, 2026https://github.com/nodejs/node/issues/64214#event-31308321868
ut only released either when thehttps://github.com/rasadregmi/node/commit/5397a5b5a3d93b9bde7c26eaf107226d2ff14cb9
5397a5bhttps://github.com/rasadregmi/node/commit/5397a5b5a3d93b9bde7c26eaf107226d2ff14cb9
fs: fix FileHandle close listener/ref leak in streamshttps://github.com/rasadregmi/node/commit/456d8c4e25fd0dbb10edf3269406118d5a9a2e58
456d8c4https://github.com/rasadregmi/node/commit/456d8c4e25fd0dbb10edf3269406118d5a9a2e58
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/64214
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/64214
fsIssues and PRs related to file-system APIs and the fs module.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22fs%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.