Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: retry unlink operations in rimraf
This commit adds synchronous retry logic to
the unlinkSync() calls in rimraf.

PR-URL: #30569
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
cjihrig committed Dec 10, 2019
commit 350654acd5e7bab5ebeeb6e1cce90c1ae19c9a93
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