Skip to content

[node-core-library] Own Windows folder deletion retry policy - #6231

Closed
Ian Clanton-Thuon (iclanton) wants to merge 1 commit into
microsoft:mainfrom
iclanton:fix/node-core-library-windows-delete-retries
Closed

Ian Clanton-Thuon (iclanton) wants to merge 1 commit into
microsoft:mainfrom
iclanton:fix/node-core-library-windows-delete-retries

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

Fixes #6230, addressing the follow-up feedback on #5836.

Make FileSystem.deleteFolder, deleteFolderAsync, ensureEmptyFolder, and ensureEmptyFolderAsync share a consistent Windows-only retry policy, without changing their public signatures. Also fix folder emptying on Node.js 20.9–20.11 and when the static methods are called unbound.

Details

  • Retry the entire operation only on Windows and only for errors reported as EBUSY, ENOTEMPTY, or EPERM. Allow three retries, waiting 100, 200, and 300 ms; propagate the final error through the existing exception decoration.
  • Pass maxRetries: 0 and retryDelay: 0 to Node, avoiding version-dependent native retry behavior and per-recursive-entry retry budgets. Use mockable Atomics.wait for synchronous waits and Async.sleepAsync for asynchronous waits.
  • Re-read child names on each emptying attempt with fs-extra.readdirSync/readdir, joining them with the supplied folder path instead of using Dirent.parentPath or this.
  • Create a missing folder only for ENOENT; preserve other folder read errors, including ENOTDIR when a file occupies the path.
  • In asynchronous emptying, stop starting child deletes after a failure and wait for every started delete to settle before retrying or rejecting. Prefer the first non-retryable error over retryable errors from the same attempt. Retain the limit of 10 concurrent top-level child deletes.
  • Document the retry schedule in all four methods' TSDoc. The Markdown-formatted change file also records the concurrency limit and folder read-error behavior introduced by the earlier PR.

Correction to the earlier PR's history

fs-extra 7 used its own vendored rimraf implementation (lib/remove/rimraf.js), not a dependency on rimraf@2. Its maxBusyTries: 3 retries applied only to asynchronous remove, on all platforms, with a separate counter at each recursive level. Synchronous removeSync instead had a Windows-only spin of up to 500 ms on each folder's final rmdir; exhausting that spin could return without throwing and leave the folder behind. fs-extra 10 replaced that implementation with native fs.rm/rmSync without retry options.

This change deliberately limits retries to Windows and keeps resource-exhaustion errors and move/moveAsync outside its scope.

How it was tested

On Linux with Node.js 24.22.1:

  • Heft build, TypeScript compilation, ESLint, and API Extractor passed with unchanged public API signatures.
  • Combined FileSystem.test and Async.test suites: 136 tests passed (86 filesystem tests and 50 async tests).
  • Deterministic mocked Windows failures cover all four methods, exact delays, exhausted budgets and final error identity/decoration, non-retryable and unknown errors, non-Windows behavior, disabled native retries, re-enumeration after partial deletion, and draining in-flight child deletes with error prioritization. Real filesystem tests cover existing/missing folders, unbound calls, and preserving an existing file.
  • rush prettier, git diff --cached --check, and rush change --verify --target-branch microsoft/main passed.

The Windows retry policy is tested using mocked failures and sleeps, not real file locking.

Address microsoft#6230 with a whole-operation retry budget, compatible folder enumeration, and settled async child deletes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
"changes": [
{
"packageName": "@rushstack/node-core-library",
"comment": "Retry `FileSystem` folder deletion operations on Windows only for errors reported as `EBUSY`, `ENOTEMPTY` or `EPERM`, with a shared budget of three retries and delays of 100, 200 and 300 ms. Fix `FileSystem.ensureEmptyFolder` and `FileSystem.ensureEmptyFolderAsync` compatibility with Node.js 20.9 and unbound calls, and ensure async child deletions settle before retrying or rejecting. `FileSystem.ensureEmptyFolderAsync` deletes at most 10 top-level children concurrently; `FileSystem.ensureEmptyFolder` and `FileSystem.ensureEmptyFolderAsync` throw on folder read errors other than `ENOENT`.",

@octogonz Pete Gonzalez (octogonz) Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is summarizing the implementation details. Rewrite to concisely say what the point of this change is, and who's impacted.

@iclanton

Copy link
Copy Markdown
Member Author

Superseded by #6232 at the author's request. The replacement restarts from a specification independently reviewed by Claude Opus 5.5 and GPT-5.3 Codex, incorporates the changelog feedback, and will undergo independent branch reviews to consensus. Original branch and commit history are preserved.

@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

[node-core-library] Feedback for PR #5836 (FileSystem.deleteFolder retry)

2 participants