Skip to content

Commit

Permalink
fs: add synchronous retries to rimraf
Browse files Browse the repository at this point in the history
This commit gives the synchronous version of rimraf the same
linear retry logic as the asynchronous version. Prior to this
commit, sync rimraf kept retrying the operation as soon as
possible until maxRetries was reached.

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 55a1a90 commit 5d39527
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
} = require('fs');
const { join } = require('path');
const { setTimeout } = require('timers');
const { sleep } = require('internal/util');
const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']);
const retryErrorCodes = new Set(
['EBUSY', 'EMFILE', 'ENFILE', 'ENOTEMPTY', 'EPERM']);
Expand Down Expand Up @@ -208,10 +209,13 @@ function _rmdirSync(path, options, originalErr) {
rimrafSync(join(path, child), options);
});

for (let i = 0; i < options.maxRetries + 1; i++) {
for (let i = 1; i <= options.maxRetries + 1; i++) {
try {
return rmdirSync(path, options);
} catch {} // Ignore errors.
} catch {
if (options.retryDelay > 0)
sleep(i * options.retryDelay);
}
}
}
}
Expand Down

0 comments on commit 5d39527

Please sign in to comment.