Skip to content

fix(arborist): retry bin-links on Windows EPERM#9028

Open
manzoorwanijk wants to merge 1 commit intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-windows-eperm
Open

fix(arborist): retry bin-links on Windows EPERM#9028
manzoorwanijk wants to merge 1 commit intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-windows-eperm

Conversation

@manzoorwanijk
Copy link
Contributor

@manzoorwanijk manzoorwanijk commented Feb 25, 2026

On Windows, npm install with install-strategy=linked fails with EPERM: operation not permitted during the bin-linking phase. This is hitting us on Windows CI for the Gutenberg monorepo (~200 workspace packages).

Summary

During rebuild, bin-links/fix-bin.js rewrites hashbang lines in bin files using write-file-atomic, which does a temp-file write followed by fs.rename(). On Windows, antivirus (Windows Defender) and the search indexer can transiently lock files that were just written, causing the rename to fail with EPERM.

The linked strategy amplifies this because it writes all packages into .store/ in parallel, increasing the window for antivirus lock conflicts compared to the hoisted layout.

Root cause

write-file-atomic uses bare require('fs') and has no retry logic for fs.rename. By contrast, graceful-fs already patches fs.rename on Windows with exponential backoff for EACCES/EPERM/EBUSY (up to 60s). Since write-file-atomic doesn't use graceful-fs, the rename fails immediately on the first lock conflict.

The longer-term fix is for write-file-atomic to use graceful-fs (tracked in npm/write-file-atomic#227, with a PR ready - npm/write-file-atomic#228), but in the meantime this PR adds retry logic at the arborist level.

Changes

  • Wrapped the binLinks() call in rebuild.js #createBinLinks with a new #binLinksWithRetry method that retries up to 5 times with 500ms–2.5s backoff on Windows when the error code is EPERM, EACCES, or EBUSY.
  • The retry only activates on process.platform === 'win32' — no behavior change on macOS/Linux.

Testing

We tested this approach in our fork and it resolves the issue on Windows CI for the Gutenberg monorepo.

References

Fixes #9021

@manzoorwanijk manzoorwanijk requested a review from a team as a code owner February 25, 2026 05:06
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy-windows-eperm branch from 02e5c12 to 9111028 Compare February 25, 2026 05:11
…y install

On Windows, antivirus and search indexer can transiently lock files,
causing write-file-atomic's fs.rename to fail with EPERM during the
bin-linking phase. The linked strategy amplifies this by writing many
store entries in parallel.

Add retry with backoff (up to 5 attempts) for EPERM/EACCES/EBUSY
errors in #createBinLinks, Windows only.
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy-windows-eperm branch from 9111028 to bff4ae0 Compare February 25, 2026 05:18
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

Successfully merging this pull request may close these issues.

[BUG] EPERM on Windows with install-strategy=linked: fs.rename fails in write-file-atomic

1 participant