Skip to content

Commit 79e92fb

Browse files
cjihrigtargos
authored andcommitted
fs: add retryDelay option to rimraf
This commit adds a retryDelay option to rimraf which configures the amount of time between retry operations. Refs: #30580 PR-URL: #30644 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0a33f17 commit 79e92fb

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

doc/api/fs.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -3224,7 +3224,8 @@ changes:
32243224
pr-url: https://github.com/nodejs/node/pull/30644
32253225
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
32263226
default is 0. The `emfileWait` option has been removed, and
3227-
`EMFILE` errors use the same retry logic as other errors.
3227+
`EMFILE` errors use the same retry logic as other errors. The
3228+
`retryDelay` option is now supported.
32283229
- version: v12.10.0
32293230
pr-url: https://github.com/nodejs/node/pull/29168
32303231
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -3249,12 +3250,15 @@ changes:
32493250
* `options` {Object}
32503251
* `maxRetries` {integer} If an `EBUSY`, `EMFILE`, `ENOTEMPTY`, or `EPERM`
32513252
error is encountered, Node.js will retry the operation with a linear backoff
3252-
wait of 100ms longer on each try. This option represents the number of
3253-
retries. This option is ignored if the `recursive` option is not `true`.
3253+
wait of `retryDelay` ms longer on each try. This option represents the number
3254+
of retries. This option is ignored if the `recursive` option is not `true`.
32543255
**Default:** `0`.
32553256
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
32563257
recursive mode, errors are not reported if `path` does not exist, and
32573258
operations are retried on failure. **Default:** `false`.
3259+
* `retryDelay` {integer} The amount of time in milliseconds to wait between
3260+
retries. This option is ignored if the `recursive` option is not `true`.
3261+
**Default:** `100`.
32583262
* `callback` {Function}
32593263
* `err` {Error}
32603264

@@ -3272,7 +3276,8 @@ changes:
32723276
pr-url: https://github.com/nodejs/node/pull/30644
32733277
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
32743278
default is 0. The `emfileWait` option has been removed, and
3275-
`EMFILE` errors use the same retry logic as other errors.
3279+
`EMFILE` errors use the same retry logic as other errors. The
3280+
`retryDelay` option is now supported.
32763281
- version: v12.10.0
32773282
pr-url: https://github.com/nodejs/node/pull/29168
32783283
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -3294,6 +3299,9 @@ changes:
32943299
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
32953300
recursive mode, errors are not reported if `path` does not exist, and
32963301
operations are retried on failure. **Default:** `false`.
3302+
* `retryDelay` {integer} The amount of time in milliseconds to wait between
3303+
retries. This option is ignored if the `recursive` option is not `true`.
3304+
**Default:** `100`.
32973305

32983306
Synchronous rmdir(2). Returns `undefined`.
32993307

@@ -5005,7 +5013,8 @@ changes:
50055013
pr-url: https://github.com/nodejs/node/pull/30644
50065014
description: The `maxBusyTries` option is renamed to `maxRetries`, and its
50075015
default is 0. The `emfileWait` option has been removed, and
5008-
`EMFILE` errors use the same retry logic as other errors.
5016+
`EMFILE` errors use the same retry logic as other errors. The
5017+
`retryDelay` option is now supported.
50095018
- version: v12.10.0
50105019
pr-url: https://github.com/nodejs/node/pull/29168
50115020
description: The `recursive`, `maxBusyTries`, and `emfileWait` options are
@@ -5018,12 +5027,15 @@ changes:
50185027
* `options` {Object}
50195028
* `maxRetries` {integer} If an `EBUSY`, `EMFILE`, `ENOTEMPTY`, or `EPERM`
50205029
error is encountered, Node.js will retry the operation with a linear backoff
5021-
wait of 100ms longer on each try. This option represents the number of
5022-
retries. This option is ignored if the `recursive` option is not `true`.
5030+
wait of `retryDelay` ms longer on each try. This option represents the number
5031+
of retries. This option is ignored if the `recursive` option is not `true`.
50235032
**Default:** `0`.
50245033
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
50255034
recursive mode, errors are not reported if `path` does not exist, and
50265035
operations are retried on failure. **Default:** `false`.
5036+
* `retryDelay` {integer} The amount of time in milliseconds to wait between
5037+
retries. This option is ignored if the `recursive` option is not `true`.
5038+
**Default:** `100`.
50275039
* Returns: {Promise}
50285040

50295041
Removes the directory identified by `path` then resolves the `Promise` with

lib/internal/fs/rimraf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function rimraf(path, options, callback) {
3535
if (err) {
3636
if (retryErrorCodes.has(err.code) && retries < options.maxRetries) {
3737
retries++;
38-
return setTimeout(_rimraf, retries * 100, path, options, CB);
38+
const delay = retries * options.retryDelay;
39+
return setTimeout(_rimraf, delay, path, options, CB);
3940
}
4041

4142
// The file is already gone.

lib/internal/fs/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
const { once } = require('internal/util');
2525
const { toPathIfFileURL } = require('internal/url');
2626
const {
27+
validateInt32,
2728
validateUint32
2829
} = require('internal/validators');
2930
const pathModule = require('path');
@@ -562,6 +563,7 @@ function warnOnNonPortableTemplate(template) {
562563
}
563564

564565
const defaultRmdirOptions = {
566+
retryDelay: 100,
565567
maxRetries: 0,
566568
recursive: false,
567569
};
@@ -577,6 +579,7 @@ const validateRmdirOptions = hideStackFrames((options) => {
577579
if (typeof options.recursive !== 'boolean')
578580
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', options.recursive);
579581

582+
validateInt32(options.retryDelay, 'retryDelay', 0);
580583
validateUint32(options.maxRetries, 'maxRetries');
581584

582585
return options;

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

+11
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ function removeAsync(dir) {
155155
// Test input validation.
156156
{
157157
const defaults = {
158+
retryDelay: 100,
158159
maxRetries: 0,
159160
recursive: false
160161
};
161162
const modified = {
163+
retryDelay: 953,
162164
maxRetries: 5,
163165
recursive: true
164166
};
@@ -169,6 +171,7 @@ function removeAsync(dir) {
169171
assert.deepStrictEqual(validateRmdirOptions({
170172
maxRetries: 99
171173
}), {
174+
retryDelay: 100,
172175
maxRetries: 99,
173176
recursive: false
174177
});
@@ -193,6 +196,14 @@ function removeAsync(dir) {
193196
});
194197
});
195198

199+
common.expectsError(() => {
200+
validateRmdirOptions({ retryDelay: -1 });
201+
}, {
202+
code: 'ERR_OUT_OF_RANGE',
203+
type: RangeError,
204+
message: /^The value of "retryDelay" is out of range\./
205+
});
206+
196207
common.expectsError(() => {
197208
validateRmdirOptions({ maxRetries: -1 });
198209
}, {

0 commit comments

Comments
 (0)