Title: fs.mkdtempDisposableSync() / fsPromises.mkdtempDisposable() throw and leak the directory when the path is a Buffer · Issue #66593 · nodejs/node · GitHub
Open Graph Title: fs.mkdtempDisposableSync() / fsPromises.mkdtempDisposable() throw and leak the directory when the path is a Buffer · Issue #66593 · nodejs/node
X Title: fs.mkdtempDisposableSync() / fsPromises.mkdtempDisposable() throw and leak the directory when the path is a Buffer · Issue #66593 · nodejs/node
Description: Node.js JavaScript runtime ✨🐢🚀✨. Contribute to nodejs/node development by creating an account on GitHub.
Open Graph Description: Node.js JavaScript runtime ✨🐢🚀✨. Contribute to nodejs/node development by creating an account on GitHub.
X Description: Node.js JavaScript runtime ✨🐢🚀✨. Contribute to nodejs/node development by creating an account on GitHub.
Opengraph URL: https://github.com/nodejs/node
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"fs.mkdtempDisposableSync() / fsPromises.mkdtempDisposable() throw and leak the directory when the path is a Buffer","articleBody":"### Version\n\nv27.0.0-nightly20261007aa1bf2cc37 (main at 6d5e309871)\n\n### Platform\n\nLinux x64\n\n### Subsystem\n\nfs\n\n### What steps will reproduce the bug?\n\n```js\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\n\nconst base = fs.mkdtempSync(path.join(os.tmpdir(), 'repro-'));\nconst prefix = path.join(base, 'x-');\n\nfor (const args of [[Buffer.from(prefix)], [prefix, { encoding: 'buffer' }]]) {\n try {\n fs.mkdtempDisposableSync(...args);\n } catch (err) {\n console.log(err.message);\n console.log('left behind:', fs.readdirSync(base));\n }\n}\n```\n\n`fs.promises.mkdtempDisposable()` behaves the same way.\n\n### How often does it reproduce? Is there a required condition?\n\nAlways, whenever the created path is a Buffer: the prefix is a Buffer, or `encoding` is `'buffer'`.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nBoth calls return the disposable object with a Buffer `path`, and `remove()` deletes the directory. The docs list `path` as `{string|Buffer}`, and since #64397 a Buffer prefix defaults `encoding` to `'buffer'`.\n\n### What do you see instead?\n\n```\nThe \"paths[1]\" argument must be of type string. Received an instance of Buffer\nleft behind: [ 'x-Kx8KEG' ]\nThe \"paths[1]\" argument must be of type string. Received an instance of Buffer\nleft behind: [ 'x-Kx8KEG', 'x-gV98fq' ]\n```\n\nThe `ERR_INVALID_ARG_TYPE` is thrown after the directory has been created. The caller never gets the disposable object, so nothing removes the directory.\n\n### Additional information\n\nAfter `binding.mkdtemp()` creates the directory, both functions stash its absolute path for `remove()` with `pathModule.resolve(cwd, path)`, and `path.resolve()` only accepts strings. The `{ encoding: 'buffer' }` form has failed this way since `mkdtempDisposable()` was added in #58516; #64397 made every Buffer prefix take the same path.\n\nI have a fix and will open a PR.\n","author":{"url":"https://github.com/gengjiawen","@type":"Person","name":"gengjiawen"},"datePublished":"2026-10-08T06:52:52Z","url":"https://github.com/nodejs/node/issues/66593"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:6bac7e41-27ec-323d-1490-340f2068740f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8388:B3C94:4320F0:573C8E:6AED2237 |
| html-safe-nonce | 854da82d70b79a0da0d9f27ec30d63ff14303f9af60d2072637c9e4f3cbe2c49 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mzg4OkIzQzk0OjQzMjBGMDo1NzNDOEU6NkFFRDIyMzciLCJ2aXNpdG9yX2lkIjoiNzQ1NTEzMTIzNjkyNjU2Mjg3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ab7a47a79015f5a2017e324fa551bb034de2f2b03d2e0d95f8ef8bfb6409f088 |
| hovercard-subject-tag | repository:27193779 |
| 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/nodejs/node/issues/66593 |
| twitter:image | https://opengraph.githubassets.com/495326f65e226f3772556773a0910e16c532881a95d78ab4dc86716d0732686f/nodejs/node |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/495326f65e226f3772556773a0910e16c532881a95d78ab4dc86716d0732686f/nodejs/node |
| og:image:alt | Node.js JavaScript runtime ✨🐢🚀✨. Contribute to nodejs/node development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6 |
| turbo-cache-control | no-cache |
| 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 | 707a24b346ac8a82878b9c084efaa38a997660cb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width