Skip to content

Commit 8bbd051

Browse files
xqinzkat
authored andcommitted
fix(git): limit retry times, avoid unlimited retries (#172)
1 parent 92f5e4c commit 8bbd051

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: lib/util/git.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const GIT_TRANSIENT_ERRORS = [
4040

4141
const GIT_TRANSIENT_ERROR_RE = new RegExp(GIT_TRANSIENT_ERRORS)
4242

43-
function shouldRetry (error) {
44-
return GIT_TRANSIENT_ERROR_RE.test(error)
43+
const GIT_TRANSIENT_ERROR_MAX_RETRY_NUMBER = 3
44+
45+
function shouldRetry (error, number) {
46+
return GIT_TRANSIENT_ERROR_RE.test(error) && (number < GIT_TRANSIENT_ERROR_MAX_RETRY_NUMBER)
4547
}
4648

4749
const GIT_ = 'GIT_'
@@ -188,7 +190,7 @@ function execGit (gitArgs, gitOpts, opts) {
188190
opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number)
189191
}
190192
return execFileAsync(gitPath, gitArgs, mkOpts(gitOpts, opts)).catch((err) => {
191-
if (shouldRetry(err)) {
193+
if (shouldRetry(err, number)) {
192194
retry(err)
193195
} else {
194196
throw err
@@ -219,7 +221,7 @@ function spawnGit (gitArgs, gitOpts, opts) {
219221
child.stderr.on('data', d => { stderr += d })
220222

221223
return finished(child, true).catch(err => {
222-
if (shouldRetry(stderr)) {
224+
if (shouldRetry(stderr, number)) {
223225
retry(err)
224226
} else {
225227
err.stderr = stderr

0 commit comments

Comments
 (0)