From 26991d0831e356c9ab86fa6cd0823afeaa0ec950 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 3 Dec 2019 23:54:35 -0500 Subject: fs: add synchronous retries to rimraf 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: 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 Reviewed-By: Richard Lau --- lib/internal/fs/rimraf.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 60310e1cf9..d6330fbe43 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -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']); @@ -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); + } } } } -- cgit v1.2.3