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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Dec 9, 2019
1 parent 5523950 commit 7e1dee3
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 7e1dee3

Please sign in to comment.