Title: fs.cpSync fails with EACCES when the destination is on a Docker bind mount (regression in 22.17) · Issue #65497 · nodejs/node · GitHub
Open Graph Title: fs.cpSync fails with EACCES when the destination is on a Docker bind mount (regression in 22.17) · Issue #65497 · nodejs/node
X Title: fs.cpSync fails with EACCES when the destination is on a Docker bind mount (regression in 22.17) · Issue #65497 · nodejs/node
Description: Version v22.17.1 (also v22.18.0, v22.20.0, v22.23.2, v24.19.0). Last good: v22.16.0. Platform Docker Desktop on macOS (Darwin 25.5.0, arm64), default VirtioFS file sharing. Reproduced with the official node:*-slim images, so the containe...
Open Graph Description: Version v22.17.1 (also v22.18.0, v22.20.0, v22.23.2, v24.19.0). Last good: v22.16.0. Platform Docker Desktop on macOS (Darwin 25.5.0, arm64), default VirtioFS file sharing. Reproduced with the offi...
X Description: Version v22.17.1 (also v22.18.0, v22.20.0, v22.23.2, v24.19.0). Last good: v22.16.0. Platform Docker Desktop on macOS (Darwin 25.5.0, arm64), default VirtioFS file sharing. Reproduced with the offi...
Opengraph URL: https://github.com/nodejs/node/issues/65497
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"fs.cpSync fails with EACCES when the destination is on a Docker bind mount (regression in 22.17)","articleBody":"### Version\n\nv22.17.1 (also v22.18.0, v22.20.0, v22.23.2, v24.19.0). Last good: **v22.16.0**.\n\n### Platform\n\nDocker Desktop on macOS (Darwin 25.5.0, arm64), default VirtioFS file sharing. Reproduced with the official `node:*-slim` images, so the container distro is Debian bookworm.\n\n### Subsystem\n\nfs\n\n### What steps will reproduce the bug?\n\n`fs.cpSync(src, dest, { recursive: true })` throws `EACCES` when `dest` is on a Docker bind mount. The same call succeeds on 22.16.0, and on 22.17.1 it succeeds when `dest` is on the container's own filesystem.\n\nOn a macOS host:\n\n```bash\nmkdir -p /tmp/repro/src/nested\nprintf 'a' > /tmp/repro/src/file.txt\nprintf 'b' > /tmp/repro/src/nested/inner.txt\n\nfor V in 22.16 22.17; do\n docker run --rm -v /tmp/repro:/mnt/repro -w /mnt/repro node:$V-slim node -e \"\nconst fs = require('fs');\nconst dest = 'out-' + process.version.replace(/[^0-9]/g, '_');\ntry { fs.cpSync('src', dest, { recursive: true }); console.log(process.version, 'OK'); }\ncatch (e) { console.log(process.version, 'FAIL', e.code, e.syscall, e.path); }\n\"\ndone\n```\n\nOutput:\n\n```\nv22.16.0 OK\nv22.17.1 FAIL EACCES cp out-_22_17_1\n```\n\n### How often does it reproduce?\n\nEvery time, on every version from 22.17.1 onward that I tested.\n\n### What is the expected behavior?\n\n`cpSync` copies the tree, as it does on 22.16.0 and as `cp -R` does on the same path in the same container.\n\n### What do you see instead?\n\n```\nError: EACCES: permission denied, cp 'out-_22_17_1'\n```\n\n### Additional information\n\n**This is not a permission problem.** In a single container run on 22.17.1, with the bind mount as CWD:\n\n```\nnode v22.17.1\n FAIL dest on bind mount EACCES cp bind-dest\n OK dest on container fs\n control: id=0 access(W_OK)=yes\n control: mkdirSync on bind mount OK\n control: copyFileSync on bind mount OK\n control: cp -R OK\n```\n\nSo, on the very path that `cpSync` rejects:\n\n- the process is **root** (uid 0) — it also fails as a non-root uid matching the host owner;\n- `fs.accessSync(dir, W_OK)` succeeds;\n- `fs.mkdirSync` succeeds;\n- `fs.copyFileSync` succeeds;\n- coreutils `cp -R` succeeds;\n- `fs.cpSync` with the **same source** and a destination on the container's own filesystem succeeds.\n\nOnly the combination of `cpSync` + a bind-mount destination fails.\n\n`cpSync` does partially complete before throwing: the destination directory is created and at least one entry is copied, so a retry then sees `EEXIST`/`ENOTEMPTY`. That makes the failure messy to recover from in a build pipeline.\n\n**Bisect** (identical mount, source, destination and uid; only the Node binary varies):\n\n| Version | Result |\n| ------- | ------ |\n| 22.13.1 | OK |\n| 22.14.0 | OK |\n| 22.16.0 | OK |\n| 22.17.1 | EACCES |\n| 22.18.0 | EACCES |\n| 22.20.0 | EACCES |\n| 22.23.2 | EACCES |\n| 24.19.0 | EACCES |\n\nThe boundary lines up with the C++ reimplementation of `cpSync`, which landed in 22.17. The mechanism is below.\n\n**Real-world impact.** `@nx/next:build` finishes by copying the app's `public/` directory into its output path with exactly this call:\n\n```js\ncpSync(join(projectRoot, 'public'), join(options.outputPath, 'public'), {\n dereference: true,\n recursive: true,\n});\n```\n\nAny Next.js build run inside a container against a bind-mounted workspace therefore fails on Node ≥ 22.17 — after the build has already compiled and typechecked successfully, so it presents as a mysterious late-stage permission error rather than an obvious environment problem. Related historical regressions in the same function: #54285, #54782.\n\n**Root cause.** Reduced to raw syscalls in the container, as root:\n\n```\nFAIL open dest O_WRONLY|O_CREAT|O_TRUNC mode 0200 errno=13 (Permission denied)\nOK open dest O_WRONLY|O_CREAT|O_TRUNC mode 0644\nFAIL reopen the 0200 file O_WRONLY errno=13 (Permission denied)\n```\n\nlibstdc++'s `do_copy_file` creates the destination with `S_IWUSR` (0200) and `fchmod`s it to the source's mode afterwards. This mount refuses to open a mode-0200 file for writing, so the create fails. `uv_fs_copyfile` creates the destination with the source's mode and is unaffected.\n\nThat is confirmed outside Node entirely — plain C++ with gcc 14 and libstdc++, same mount:\n\n```\nFAIL copy_file mount -> mount value=13 msg=Permission denied\nOK copy_file mount -> /tmp\nOK copy_file /tmp -> /tmp\nFAIL copy_file /tmp -> mount value=13 msg=Permission denied\n```\n\n**Which is why `cpSync` is inconsistent with itself**, on one mount in one process:\n\n| Call | Result | Path taken |\n| ---- | ------ | ---------- |\n| `cpSync(file, newDest)` | OK | JS falls through to `copyFileSync` (libuv) |\n| `cpSync(file, existingDest)` | EACCES | `CpSyncOverrideFile`, `mode == 0` branch |\n| `cpSync(dirWithAFile, dest)` | EACCES | `CpSyncCopyDir`, regular-file branch |\n| `cpSync(dirNoFiles, dest)` | OK | no file is ever copied |\n\n`fs.copyFileSync` works on this mount because it uses `uv_fs_copyfile`. Both failing paths already have a libuv sibling in `node_file.cc`; they just do not take it.\n\n**Workaround.** Pin to 22.16.x, or arrange for the destination to live on the container's own filesystem rather than the bind mount.","author":{"url":"https://github.com/mnaimfaizy","@type":"Person","name":"mnaimfaizy"},"datePublished":"2026-08-23T01:37:39Z","url":"https://github.com/nodejs/node/issues/65497"}
| 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:94b4ae4b-f93d-3f2a-ad7d-79684a6e4510 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9B6:197704:C5165D:10082F9:6AED4AB0 |
| html-safe-nonce | 1b473a42eab1c8474e6642c685bd623e2b09b6ed1afa0f99a35ca5b201388236 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUI2OjE5NzcwNDpDNTE2NUQ6MTAwODJGOTo2QUVENEFCMCIsInZpc2l0b3JfaWQiOiI4Nzc3OTk2NzE2MTcxMTUyMDQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 463edb181879d22b541236ab36beab77188a23e028301df4926566672ecd426b |
| hovercard-subject-tag | issue:5224809219 |
| 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/65497/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5310ba6d40a1f5f9a42fb18057f46ab53fd2f71500f5e81aa35c50f477cf2718/nodejs/node/issues/65497 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5310ba6d40a1f5f9a42fb18057f46ab53fd2f71500f5e81aa35c50f477cf2718/nodejs/node/issues/65497 |
| og:image:alt | Version v22.17.1 (also v22.18.0, v22.20.0, v22.23.2, v24.19.0). Last good: v22.16.0. Platform Docker Desktop on macOS (Darwin 25.5.0, arm64), default VirtioFS file sharing. Reproduced with the offi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mnaimfaizy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11 |
| 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 | 9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width