Title: `fs.rmSync(path, { recursive: true, maxRetries: manyManyRetries})` throws on `ENFILE` · Issue #55555 · nodejs/node · GitHub
Open Graph Title: `fs.rmSync(path, { recursive: true, maxRetries: manyManyRetries})` throws on `ENFILE` · Issue #55555 · nodejs/node
X Title: `fs.rmSync(path, { recursive: true, maxRetries: manyManyRetries})` throws on `ENFILE` · Issue #55555 · nodejs/node
Description: Version v22.8.0 Platform Linux tumba 6.11.4-gentoo-yuran-r7 #8 SMP Sat Oct 19 16:45:43 +08 2024 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 GenuineIntel GNU/Linux Subsystem fs What steps will reproduce the bug? Set low limits or high FILE_CO...
Open Graph Description: Version v22.8.0 Platform Linux tumba 6.11.4-gentoo-yuran-r7 #8 SMP Sat Oct 19 16:45:43 +08 2024 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 GenuineIntel GNU/Linux Subsystem fs What steps will reproduce...
X Description: Version v22.8.0 Platform Linux tumba 6.11.4-gentoo-yuran-r7 #8 SMP Sat Oct 19 16:45:43 +08 2024 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 GenuineIntel GNU/Linux Subsystem fs What steps will reproduce...
Opengraph URL: https://github.com/nodejs/node/issues/55555
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`fs.rmSync(path, { recursive: true, maxRetries: manyManyRetries})` throws on `ENFILE`","articleBody":"### Version\n\nv22.8.0\n\n### Platform\n\n```text\nLinux tumba 6.11.4-gentoo-yuran-r7 #8 SMP Sat Oct 19 16:45:43 +08 2024 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 GenuineIntel GNU/Linux\n```\n\n\n### Subsystem\n\nfs\n\n### What steps will reproduce the bug?\n\nSet low limits or high `FILE_COUNT`, run the following:\r\n\r\n```mjs\r\nimport fs from 'node:fs';\r\nimport { readFile } from 'node:fs/promises';\r\n\r\nconst OUTPUT_DIRECTORY = \"/tmp/emfile-check\";\r\nconst FILE_COUNT = 150_000; // adjust this according to ulimit -n, ulimit -Hn, /proc/sys/fs/file-max, etc.\r\n\r\nfunction generateFiles() {\r\n fs.rmSync(OUTPUT_DIRECTORY, { recursive: true, force: true, maxRetries: 8192 });\r\n fs.mkdirSync(OUTPUT_DIRECTORY, { recursive: true });\r\n for (let i = 0; i \u003c FILE_COUNT; i++) {\r\n const fileName = `file_${i}.js`;\r\n const fileContent = `// This is file ${i}`;\r\n fs.writeFileSync(`${OUTPUT_DIRECTORY}/${fileName}`, fileContent);\r\n }\r\n}\r\n\r\nfunction generateEmFileError() {\r\n return Promise.all(\r\n Array.from({ length: FILE_COUNT }, (_, i) => {\r\n const fileName = `file_${i}.js`;\r\n return readFile(`${OUTPUT_DIRECTORY}/${fileName}`);\r\n })\r\n );\r\n}\r\n\r\nconsole.log(`Generating ${FILE_COUNT} files in ${OUTPUT_DIRECTORY}...`);\r\ngenerateFiles();\r\n\r\nconsole.log(\"Checking that this number of files would cause an EMFILE error...\");\r\nawait generateEmFileError()\r\n .then(() => {\r\n throw new Error(\"Test failure: not enough files to encounter EMFILE.\");\r\n })\r\n .catch(error => {\r\n if (error.code === \"EMFILE\") {\r\n console.log(\"Successfully got intentional EMFILE:\", error.message);\r\n } else if (error.code === \"ENFILE\") {\r\n console.log(\"Successfully got intentional ENFILE:\", error.message);\r\n } else {\r\n console.error(\"Failed with unknown error:\", error.message);\r\n throw error;\r\n }\r\n })\r\n .finally(() => {\r\n console.log(`Attempting to remove ${OUTPUT_DIRECTORY}`);\r\n fs.rmSync(OUTPUT_DIRECTORY, { recursive: true, force: true, maxRetries: 8192 });\r\n console.log(`Successfully removed ${OUTPUT_DIRECTORY}`);\r\n });\r\n```\n\n### How often does it reproduce? Is there a required condition?\n\nMight be flaky depending on system configuration (under some conditions exhausting fd limits may render system unresponsive).\n\n### What is the expected behavior? Why is that the expected behavior?\n\n```\r\nGenerating 150000 files in /tmp/emfile-check...\r\nChecking that this number of files would cause an EMFILE error...\r\nSuccessfully got intentional ENFILE: ENFILE: file table overflow, open '/tmp/emfile-check/file_63275.js'\r\nAttempting to remove /tmp/emfile-check\r\nSuccessfully removed /tmp/emfile-check\r\n```\r\nWe should encounter the ENFILE via `generateEmFileError` function, catch the error, and remove the directory. Directory removal might encounter errors due to unfinished jobs, but it should retry with 100ms delay 8192 times (more than 13 minutes).\n\n### What do you see instead?\n\n```\r\nGenerating 150000 files in /tmp/emfile-check...\r\nChecking that this number of files would cause an EMFILE error...\r\nSuccessfully got intentional ENFILE: ENFILE: file table overflow, open '/tmp/emfile-check/file_63275.js'\r\nAttempting to remove /tmp/emfile-check\r\nnode:fs:1502\r\n const result = binding.readdir(\r\n ^\r\n\r\nError: ENFILE: file table overflow, scandir '/tmp/emfile-check'\r\n at readdirSync (node:fs:1502:26)\r\n at _rmdirSync (node:internal/fs/rimraf:249:29)\r\n at rimrafSync (node:internal/fs/rimraf:192:7)\r\n at Object.rmSync (node:fs:1247:10)\r\n at file:///tmp/repro/t.mjs:52:8\r\n at \u003canonymous>\r\n at async file:///tmp/repro/t.mjs:36:1 {\r\n errno: -23,\r\n code: 'ENFILE',\r\n syscall: 'scandir',\r\n path: '/tmp/emfile-check'\r\n}\r\n\r\nNode.js v22.8.0\r\n```\n\n### Additional information\n\nAccording to the [docs](https://nodejs.org/api/fs.html#fsrmsyncpath-options), it must continue in case of `ENFILE`.","author":{"url":"https://github.com/LiviaMedeiros","@type":"Person","name":"LiviaMedeiros"},"datePublished":"2024-10-26T18:01:19Z","url":"https://github.com/nodejs/node/issues/55555"}
| 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:17b629a1-49e8-6c95-2089-56de95c0aba8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF60:BAC69:6ED584:973ADF:6AED2C15 |
| html-safe-nonce | 5677d80e5fb5dfc316b5034c4fd2d07b226fa35a95951065ab3e5f3c2c1b3bf4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjYwOkJBQzY5OjZFRDU4NDo5NzNBREY6NkFFRDJDMTUiLCJ2aXNpdG9yX2lkIjoiODk2NzUxOTY1MTQxNTAxMDMyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 57ac9d418084e9301cdedcae23badf6fac362e4acd23ef809a59ed741124aef7 |
| hovercard-subject-tag | issue:2616040391 |
| 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/55555/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ebbc5a5dfd19a775955e6059fb8795dafa8ef1e55b3bb3a817101fc0f906db54/nodejs/node/issues/55555 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ebbc5a5dfd19a775955e6059fb8795dafa8ef1e55b3bb3a817101fc0f906db54/nodejs/node/issues/55555 |
| og:image:alt | Version v22.8.0 Platform Linux tumba 6.11.4-gentoo-yuran-r7 #8 SMP Sat Oct 19 16:45:43 +08 2024 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 GenuineIntel GNU/Linux Subsystem fs What steps will reproduce... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LiviaMedeiros |
| 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