Skip to content

Commit 022ecbd

Browse files
cjihrigtargos
authored andcommitted
fs: make rimraf default to 0 retries
This commit makes retries an opt-in feature by defaulting to no automatic retries. This will be particularly important once synchronous operations can sleep between attempts. Refs: #30580 PR-URL: #30644 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent dfb86f9 commit 022ecbd

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

doc/api/fs.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,8 @@ added: v0.0.2
32223222
changes:
32233223
- version: REPLACEME
32243224
pr-url: https://github.com/nodejs/node/pull/30644
3225-
description: The `maxBusyTries` option is renamed to `maxRetries`.
3225+
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
3226+
default is 0.
32263227
- version: v12.10.0
32273228
pr-url: https://github.com/nodejs/node/pull/29168
32283229
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -3252,7 +3253,7 @@ changes:
32523253
* `maxRetries` {integer} If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error is
32533254
encountered, Node.js will retry the operation with a linear backoff wait of
32543255
100ms longer on each try. This option represents the number of retries. This
3255-
option is ignored if the `recursive` option is not `true`. **Default:** `3`.
3256+
option is ignored if the `recursive` option is not `true`. **Default:** `0`.
32563257
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
32573258
recursive mode, errors are not reported if `path` does not exist, and
32583259
operations are retried on failure. **Default:** `false`.
@@ -3271,7 +3272,8 @@ added: v0.1.21
32713272
changes:
32723273
- version: REPLACEME
32733274
pr-url: https://github.com/nodejs/node/pull/30644
3274-
description: The `maxBusyTries` option is renamed to `maxRetries`.
3275+
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
3276+
default is 0.
32753277
- version: v12.10.0
32763278
pr-url: https://github.com/nodejs/node/pull/29168
32773279
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -3286,6 +3288,10 @@ changes:
32863288
32873289
* `path` {string|Buffer|URL}
32883290
* `options` {Object}
3291+
* `maxRetries` {integer} If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error is
3292+
encountered, Node.js will retry the operation. This option represents the
3293+
number of retries. This option is ignored if the `recursive` option is not
3294+
`true`. **Default:** `0`.
32893295
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
32903296
recursive mode, errors are not reported if `path` does not exist, and
32913297
operations are retried on failure. **Default:** `false`.
@@ -4998,7 +5004,8 @@ added: v10.0.0
49985004
changes:
49995005
- version: REPLACEME
50005006
pr-url: https://github.com/nodejs/node/pull/30644
5001-
description: The `maxBusyTries` option is renamed to `maxRetries`.
5007+
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
5008+
default is 0.
50025009
- version: v12.10.0
50035010
pr-url: https://github.com/nodejs/node/pull/29168
50045011
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -5016,7 +5023,7 @@ changes:
50165023
* `maxRetries` {integer} If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error is
50175024
encountered, Node.js will retry the operation with a linear backoff wait of
50185025
100ms longer on each try. This option represents the number of retries. This
5019-
option is ignored if the `recursive` option is not `true`. **Default:** `3`.
5026+
option is ignored if the `recursive` option is not `true`. **Default:** `0`.
50205027
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
50215028
recursive mode, errors are not reported if `path` does not exist, and
50225029
operations are retried on failure. **Default:** `false`.

lib/internal/fs/rimraf.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']);
2525
const isWindows = process.platform === 'win32';
2626
const epermHandler = isWindows ? fixWinEPERM : _rmdir;
2727
const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync;
28-
const numRetries = isWindows ? 100 : 1;
2928

3029

3130
function rimraf(path, options, callback) {
3231
let timeout = 0; // For EMFILE handling.
33-
let busyTries = 0;
32+
let retries = 0;
3433

3534
_rimraf(path, options, function CB(err) {
3635
if (err) {
3736
if ((err.code === 'EBUSY' || err.code === 'ENOTEMPTY' ||
38-
err.code === 'EPERM') && busyTries < options.maxRetries) {
39-
busyTries++;
40-
return setTimeout(_rimraf, busyTries * 100, path, options, CB);
37+
err.code === 'EPERM') && retries < options.maxRetries) {
38+
retries++;
39+
return setTimeout(_rimraf, retries * 100, path, options, CB);
4140
}
4241

4342
if (err.code === 'EMFILE' && timeout < options.emfileWait)
@@ -211,7 +210,7 @@ function _rmdirSync(path, options, originalErr) {
211210
rimrafSync(join(path, child), options);
212211
});
213212

214-
for (let i = 0; i < numRetries; i++) {
213+
for (let i = 0; i < options.maxRetries + 1; i++) {
215214
try {
216215
return rmdirSync(path, options);
217216
} catch {} // Ignore errors.

lib/internal/fs/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ function warnOnNonPortableTemplate(template) {
564564

565565
const defaultRmdirOptions = {
566566
emfileWait: 1000,
567-
maxRetries: 3,
567+
maxRetries: 0,
568568
recursive: false,
569569
};
570570

test/parallel/test-fs-rmdir-recursive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function removeAsync(dir) {
156156
{
157157
const defaults = {
158158
emfileWait: 1000,
159-
maxRetries: 3,
159+
maxRetries: 0,
160160
recursive: false
161161
};
162162
const modified = {

0 commit comments

Comments
 (0)