Skip to content

Commit

Permalink
fs: retry unlink operations in rimraf
Browse files Browse the repository at this point in the history
This commit adds synchronous retry logic to
the unlinkSync() calls in rimraf.

PR-URL: #30569
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ben Coe <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Dec 11, 2019
1 parent 5e98de1 commit 18758ef
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function rimrafSync(path, options) {
if (stats !== undefined && stats.isDirectory())
_rmdirSync(path, options, null);
else
unlinkSync(path);
_unlinkSync(path, options);
} catch (err) {
if (err.code === 'ENOENT')
return;
Expand All @@ -198,6 +198,25 @@ function rimrafSync(path, options) {
}


function _unlinkSync(path, options) {
const tries = options.maxRetries + 1;

for (let i = 1; i <= tries; i++) {
try {
return unlinkSync(path);
} 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);
}
}
}
}


function _rmdirSync(path, options, originalErr) {
try {
rmdirSync(path);
Expand Down Expand Up @@ -264,7 +283,7 @@ function fixWinEPERMSync(path, options, originalErr) {
if (stats.isDirectory())
_rmdirSync(path, options, originalErr);
else
unlinkSync(path);
_unlinkSync(path, options);
}


Expand Down

0 comments on commit 18758ef

Please sign in to comment.