Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79e92fb

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0a33f17 commit 79e92fb
Copy full SHA for 79e92fb

File tree

Expand file treeCollapse file tree

4 files changed

+35
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+35
-8
lines changed
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+19-7Lines changed: 19 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
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
Collapse file

‎lib/internal/fs/rimraf.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/rimraf.js
+2-1Lines changed: 2 additions & 1 deletion
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.
Collapse file

‎lib/internal/fs/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js
+3Lines changed: 3 additions & 0 deletions
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;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-rmdir-recursive.js
+11Lines changed: 11 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.