Skip to content

fix: use graceful-fs to retry transient EPERM/EACCES/EBUSY on Windows rename#228

Open
manzoorwanijk wants to merge 1 commit intonpm:mainfrom
manzoorwanijk:fix/use-graceful-fs-for-windows-rename-retry
Open

fix: use graceful-fs to retry transient EPERM/EACCES/EBUSY on Windows rename#228
manzoorwanijk wants to merge 1 commit intonpm:mainfrom
manzoorwanijk:fix/use-graceful-fs-for-windows-rename-retry

Conversation

@manzoorwanijk
Copy link

Summary

On Windows, fs.rename fails with EPERM: operation not permitted when another process (Windows Defender, Windows Search indexer, or a concurrent Node.js worker) holds a transient lock on the target file. This is especially prominent with npm's install-strategy=linked, where many files are written in parallel under a single .store/ directory, increasing the window for antivirus lock conflicts.

The root cause is that write-file-atomic uses bare require('fs'), which has no retry logic. graceful-fs already patches fs.rename on Windows with exponential backoff (up to 60s) for EACCES/EPERM/EBUSY errors (polyfills.js#L96-L120).

This PR switches from require('fs') to require('graceful-fs') to get that retry behavior.

Background

graceful-fs was originally a dependency of write-file-atomic but was removed in v3.0.0 to break a circular dependency that interfered with graceful-fs's own test suite (isaacs/node-graceful-fs#163). That circular dependency no longer exists since tap no longer depends on write-file-atomic.

Changes

  • lib/index.js: Changed require('fs') to require('graceful-fs')
  • package.json: Added graceful-fs (^4.2.11) as a dependency
  • test/basic.js, test/concurrency.js, test/integration.js: Updated t.mock() calls to mock 'graceful-fs' instead of 'fs'

Related issues

References

Fixes #227, #28

graceful-fs patches fs.rename on Windows with exponential backoff for
EACCES/EPERM/EBUSY, fixing failures caused by antivirus or indexer
file locks during concurrent writes.

Fixes npm#227
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: fs.rename fails due to transient file locks (no retry)

1 participant