Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.rename() can crash with cross-mount renames #41

Open
depau opened this issue Sep 25, 2024 · 0 comments
Open

fs.rename() can crash with cross-mount renames #41

depau opened this issue Sep 25, 2024 · 0 comments

Comments

@depau
Copy link

depau commented Sep 25, 2024

This line:

await fs.rename(path.join(scratchDir, 'dance-cache'), cacheSource);

It fails if you specify a cache location that is in a different mountpoint than the scratch directory. This can happen on AWS CodeBuild if you place the cache directory in the home directory, like this log below.

 Post job cleanup.

FROM busybox:1
COPY buildstamp buildstamp
RUN --mount=type=cache,target=/root/.npm     mkdir -p /var/dance-cache/     && cp -p -R /root/.npm/. /var/dance-cache/ || true

Error: EXDEV: cross-device link not permitted, rename 'scratch/dance-cache' -> '/root/.cache/docker-build-cache/root/.npm'
    at async Object.rename (node:internal/fs/promises:779:10)
    at async $8d40300f3635b768$var$extractCache (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1374:5)
    at async $8d40300f3635b768$export$bd3cfa0c41fc7012 (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1384:72)
    at async $bec5d2ddaaf4a876$var$main (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1393:5)
    at async file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1401:5 {
  errno: -18,
  code: 'EXDEV',
  syscall: 'rename',
  path: 'scratch/dance-cache',
  dest: '/root/.cache/docker-build-cache/root/.npm'
}
Error: EXDEV: cross-device link not permitted, rename 'scratch/dance-cache' -> '/root/.cache/docker-build-cache/root/.npm'
    at async Object.rename (node:internal/fs/promises:779:10)
    at async $8d40300f3635b768$var$extractCache (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1374:5)
    at async $8d40300f3635b768$export$bd3cfa0c41fc7012 (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1384:72)
    at async $bec5d2ddaaf4a876$var$main (file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1393:5)
    at async file:///codebuild/output/src2102109131/src/actions-runner/_work/_actions/reproducible-containers/buildkit-cache-dance/v3.1.0/dist/index.js:1401:5

I fixed the issue in my code by simply moving the cache directory into the workspace.

I thought I'd let you know anyway, in case you want to wrap this in a try-catch and copy the directory on failure or just document this quirk.

Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant