Skip to content

Commit 7e1dee3

Browse files
cjihrigtargos
authored andcommitted
fs: reduce unnecessary sync rimraf retries
rimraf should only retry if certain errors are encountered. Additionally, there is no point sleeping if an error occurs on the last try. PR-URL: #30785Fixes: #30580 Refs: #30569 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 5523950 commit 7e1dee3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎lib/internal/fs/rimraf.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ function _rmdirSync(path, options, originalErr) {
209209
rimrafSync(join(path,child),options);
210210
});
211211

212-
for(leti=1;i<=options.maxRetries+1;i++){
212+
consttries=options.maxRetries+1;
213+
214+
for(leti=1;i<=tries;i++){
213215
try{
214216
returnrmdirSync(path,options);
215-
}catch{
216-
if(options.retryDelay>0)
217+
}catch(err){
218+
// Only sleep if this is not the last try, and the delay is greater
219+
// than zero, and an error was encountered that warrants a retry.
220+
if(retryErrorCodes.has(err.code)&&
221+
i<tries&&
222+
options.retryDelay>0){
217223
sleep(i*options.retryDelay);
224+
}
218225
}
219226
}
220227
}

0 commit comments

Comments
 (0)