Skip to content

Retry fs operations on EAGAIN error#259

Open
veeceey wants to merge 1 commit intoisaacs:mainfrom
veeceey:fix/issue-258-eagain-error
Open

Retry fs operations on EAGAIN error#259
veeceey wants to merge 1 commit intoisaacs:mainfrom
veeceey:fix/issue-258-eagain-error

Conversation

@veeceey
Copy link
Copy Markdown

@veeceey veeceey commented Feb 13, 2026

Filesystem operations can return EAGAIN to signal that the resource is temporarily unavailable and the caller should try again. This is a transient error similar to EMFILE/ENFILE, but graceful-fs wasn't retrying on it.

This showed up in practice as spurious failures in pnpm (see pnpm/pnpm#9959) and other tools that rely on graceful-fs for resilient filesystem access.

The fix adds EAGAIN to the error code checks alongside EMFILE and ENFILE in all the async fs wrappers (open, readFile, writeFile, appendFile, copyFile, readdir). The existing retry queue with exponential backoff and 60s timeout handles the rest -- EAGAIN just needed to be recognized as a retryable condition.

Note that polyfills.js already had EAGAIN handling for the lower-level fs.read/fs.readSync, so this brings the higher-level operations in line.

Tests added:

  • EAGAIN retry succeeds after transient failures (readFile, open, writeFile)
  • EAGAIN eventually times out and surfaces the error after 60s

All existing tests continue to pass.

Fixes #258

Filesystem operations can return EAGAIN to indicate a temporary resource
unavailability. This is similar to EMFILE/ENFILE but was not being
retried by graceful-fs, causing spurious failures in tools like pnpm.

Add EAGAIN to the set of retryable error codes for open, readFile,
writeFile, appendFile, copyFile, and readdir operations. The existing
retry/backoff/timeout logic already handles this correctly - EAGAIN
just needed to be recognized as a retryable condition.

Fixes isaacs#258
@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

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.

Incorrect handling of fs error EAGAIN

1 participant