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 fb2253e

Browse filesBrowse files
cjihrigtargos
authored andcommitted
fs: retry unlink operations in rimraf
This commit adds synchronous retry logic to the unlinkSync() calls in rimraf. PR-URL: #30569 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 76affb6 commit fb2253e
Copy full SHA for fb2253e

File tree

Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/fs/rimraf.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/rimraf.js
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function rimrafSync(path, options) {
190190
if (stats !== undefined && stats.isDirectory())
191191
_rmdirSync(path, options, null);
192192
else
193-
unlinkSync(path);
193+
_unlinkSync(path, options);
194194
} catch (err) {
195195
if (err.code === 'ENOENT')
196196
return;
@@ -204,6 +204,25 @@ function rimrafSync(path, options) {
204204
}
205205

206206

207+
function _unlinkSync(path, options) {
208+
const tries = options.maxRetries + 1;
209+
210+
for (let i = 1; i <= tries; i++) {
211+
try {
212+
return unlinkSync(path);
213+
} catch (err) {
214+
// Only sleep if this is not the last try, and the delay is greater
215+
// than zero, and an error was encountered that warrants a retry.
216+
if (retryErrorCodes.has(err.code) &&
217+
i < tries &&
218+
options.retryDelay > 0) {
219+
sleep(i * options.retryDelay);
220+
}
221+
}
222+
}
223+
}
224+
225+
207226
function _rmdirSync(path, options, originalErr) {
208227
try {
209228
rmdirSync(path);
@@ -270,7 +289,7 @@ function fixWinEPERMSync(path, options, originalErr) {
270289
if (stats.isDirectory())
271290
_rmdirSync(path, options, originalErr);
272291
else
273-
unlinkSync(path);
292+
_unlinkSync(path, options);
274293
}
275294

276295

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.