diff options
author | cjihrig <cjihrig@gmail.com> | 2019-12-08 10:50:04 -0500 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-12-09 07:15:29 +0100 |
commit | d7b8ae72d97557571c577a865c37e7a5b196a332 (patch) | |
tree | 9001e108a18562806a84fa6258bbc1c2cb4b919a | |
parent | 26991d0831e356c9ab86fa6cd0823afeaa0ec950 (diff) | |
download | android-node-v8-d7b8ae72d97557571c577a865c37e7a5b196a332.tar.gz android-node-v8-d7b8ae72d97557571c577a865c37e7a5b196a332.tar.bz2 android-node-v8-d7b8ae72d97557571c577a865c37e7a5b196a332.zip |
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: https://github.com/nodejs/node/pull/30785
Fixes: https://github.com/nodejs/node/issues/30580
Refs: https://github.com/nodejs/node/pull/30569
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
-rw-r--r-- | lib/internal/fs/rimraf.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index d6330fbe43..6d6b19efcc 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -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); + } } } } |