Title: fs: `fs.watch` on MacOS leaks native memory each time a directory watcher is closed and reopened · Issue #67284 · nodejs/node · GitHub
Open Graph Title: fs: `fs.watch` on MacOS leaks native memory each time a directory watcher is closed and reopened · Issue #67284 · nodejs/node
X Title: fs: `fs.watch` on MacOS leaks native memory each time a directory watcher is closed and reopened · Issue #67284 · nodejs/node
Description: Version v26.0.0 (also v24.22.1) Platform Darwin [Redacted] 25.6.0 Darwin Kernel Version 25.6.0: Tue Aug 18 17:51:47 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6050 arm64 Subsystem fs What steps will reproduce the bug? On Mac...
Open Graph Description: Version v26.0.0 (also v24.22.1) Platform Darwin [Redacted] 25.6.0 Darwin Kernel Version 25.6.0: Tue Aug 18 17:51:47 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6050 arm64 Subsystem fs W...
X Description: Version v26.0.0 (also v24.22.1) Platform Darwin [Redacted] 25.6.0 Darwin Kernel Version 25.6.0: Tue Aug 18 17:51:47 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6050 arm64 Subsystem fs W...
Opengraph URL: https://github.com/nodejs/node/issues/67284
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"fs: `fs.watch` on MacOS leaks native memory each time a directory watcher is closed and reopened","articleBody":"### Version\n\nv26.0.0 (also v24.22.1)\n\n### Platform\n\n```text\nDarwin [Redacted] 25.6.0 Darwin Kernel Version 25.6.0: Tue Aug 18 17:51:47 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6050 arm64\n```\n\n### Subsystem\n\nfs\n\n### What steps will reproduce the bug?\n\nOn MacOS, run this script using node. It closes and reopens N directory watchers and prints the mem growth as reported by `vmap`:\n```js\n import { watch, mkdtempSync, mkdirSync } from 'node:fs';\n import { tmpdir } from 'node:os';\n import { join } from 'node:path';\n import { execFileSync } from 'node:child_process';\n\n const footprintKB = () => {\n const out = execFileSync('vmmap', ['--summary', String(process.pid)]).\n toString();\n const [, n, unit] = out.match(/Physical footprint:\\s+([\\d.]+)([KMG])/);\n return Number(n) * { K: 1, M: 1024, G: 1024 * 1024 }[unit];\n };\n const tick = () => new Promise((r) => setImmediate(r));\n const sleep = (ms) => new Promise((r) => setTimeout(r, ms));\n\n for (const n of [10, 100, 400, 1000]) {\n const base = mkdtempSync(join(tmpdir(), 'fsw-'));\n const dirs = Array.from({ length: n }, (_, i) => join(base, `d${i}`));\n for (const d of dirs) mkdirSync(d);\n const watchers = dirs.map((d) => watch(d, () => {}));\n await sleep(500);\n const before = footprintKB();\n for (let i = 0; i \u003c 1000; i++) {\n watchers[0].close();\n watchers[0] = watch(dirs[0], () => {});\n if (i % 20 === 0) await tick();\n }\n await sleep(500);\n const growth = footprintKB() - before;\n console.log(`${n} watchers open: +${(growth / 1024).toFixed(1)} MB after\n 1000 reopens (${(growth / 1000).toFixed(1)} KB per reopen)`);\n for (const w of watchers) w.close();\n await sleep(500);\n }\n process.exit(0);\n\n```\n\n### How often does it reproduce? Is there a required condition?\n\nEvery run on MacOS\n\n### What is the expected behavior? Why is that the expected behavior?\n\nI would expect physical memory usage to stay about flat.\n\n### What do you see instead?\n\n```\n 10 watchers open: +4.4 MB after 1000 reopens (4.5 KB per reopen)\n 100 watchers open: +11.8 MB after 1000 reopens (12.1 KB per reopen)\n 400 watchers open: +48.8 MB after 1000 reopens (50.0 KB per reopen)\n 1000 watchers open: +114.8 MB after 1000 reopens (117.6 KB per reopen)\n```\n\n\n### Additional information\n\nThis is fixed in libuv by https://github.com/libuv/libuv/pull/5283 (\"darwin: release fsevents path allocations\"). `uv__fsevents_reschedule` rebuilds the shared FSEventStream from every watched path each time a watcher starts or stops, and did not release the path array and strings after a successful rebuild.\n\nThat commit is not in a libuv release yet. It merged after v1.53.0, so #66282 (update to libuv 1.53.0) does not include it. Could it be cherry-picked into deps/uv , as was done for aabb7651de in #62561, and backported to v24.x?\n\nDownstream report: https://github.com/oxc-project/oxc-node/issues/906\n\nI used an AI coding assistant to help find the cause and draft this report. I ran the reproduction above myself on both versions listed and checked the libuv change against src/unix/fsevents.c .\n","author":{"url":"https://github.com/howie-sola","@type":"Person","name":"howie-sola"},"datePublished":"2026-11-05T21:45:35Z","url":"https://github.com/nodejs/node/issues/67284"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6f90eb69-edc5-2be9-129d-9a5a3a1d234f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C63C:24555E:972DCD:C9538A:6AED2EBB |
| html-safe-nonce | 0c2273cba3b4c87ef56a6bd1fd853af50a3de9db88eedb028662d3f7a2ab1e0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjNDOjI0NTU1RTo5NzJEQ0Q6Qzk1MzhBOjZBRUQyRUJCIiwidmlzaXRvcl9pZCI6IjE2MjI5NzgyNTc4NzY3NTgyMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9e9000971758662ad3ef754ac1609de9c50db334138bccc316ae0ca8773d71c7 |
| hovercard-subject-tag | issue:6232221704 |
| 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/67284/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e802d0fe898145ab00049b01d09c1cd1b0cb4bd3947820840ab70879af1e896f/nodejs/node/issues/67284 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e802d0fe898145ab00049b01d09c1cd1b0cb4bd3947820840ab70879af1e896f/nodejs/node/issues/67284 |
| og:image:alt | Version v26.0.0 (also v24.22.1) Platform Darwin [Redacted] 25.6.0 Darwin Kernel Version 25.6.0: Tue Aug 18 17:51:47 PDT 2026; root:xnu-12377.161.15.700.19~2/RELEASE_ARM64_T6050 arm64 Subsystem fs W... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | howie-sola |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| 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 | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width