diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 60310e1cf9427e..d6330fbe4399a0 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); + } } } }