Skip to content

Commit 50afd34

Browse files
cjihrigtargos
authored andcommitted
fs: reduce unnecessary sync rimraf retries
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]>
1 parent 4e05bf0 commit 50afd34

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/internal/fs/rimraf.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ function _rmdirSync(path, options, originalErr) {
209209
rimrafSync(join(path, child), options);
210210
});
211211

212-
for (let i = 1; i <= options.maxRetries + 1; i++) {
212+
const tries = options.maxRetries + 1;
213+
214+
for (let i = 1; i <= tries; i++) {
213215
try {
214216
return rmdirSync(path, options);
215-
} catch {
216-
if (options.retryDelay > 0)
217+
} catch (err) {
218+
// Only sleep if this is not the last try, and the delay is greater
219+
// than zero, and an error was encountered that warrants a retry.
220+
if (retryErrorCodes.has(err.code) &&
221+
i < tries &&
222+
options.retryDelay > 0) {
217223
sleep(i * options.retryDelay);
224+
}
218225
}
219226
}
220227
}

0 commit comments

Comments
 (0)