Skip to content

Commit

Permalink
fs: reduce unnecessary sync rimraf retries
Browse files Browse the repository at this point in the history
rimraf should only retry if certain errors are encountered.
Additionally, there is no point sleeping if an error occurs
on the last try.

PR-URL: #30785
Fixes: #30580
Refs: #30569
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
cjihrig authored and BethGriggs committed Feb 6, 2020
1 parent 5d39527 commit 1d4e3d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,19 @@ function _rmdirSync(path, options, originalErr) {
rimrafSync(join(path, child), options);
});

for (let i = 1; i <= options.maxRetries + 1; i++) {
const tries = options.maxRetries + 1;

for (let i = 1; i <= tries; i++) {
try {
return rmdirSync(path, options);
} catch {
if (options.retryDelay > 0)
} catch (err) {
// Only sleep if this is not the last try, and the delay is greater
// than zero, and an error was encountered that warrants a retry.
if (retryErrorCodes.has(err.code) &&
i < tries &&
options.retryDelay > 0) {
sleep(i * options.retryDelay);
}
}
}
}
Expand Down

0 comments on commit 1d4e3d5

Please sign in to comment.