Skip to content

Commit

Permalink
fix(git): limit retry times, avoid unlimited retries (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
xqin authored and zkat committed Jun 17, 2019
1 parent 92f5e4c commit 8bbd051
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const GIT_TRANSIENT_ERRORS = [

const GIT_TRANSIENT_ERROR_RE = new RegExp(GIT_TRANSIENT_ERRORS)

function shouldRetry (error) {
return GIT_TRANSIENT_ERROR_RE.test(error)
const GIT_TRANSIENT_ERROR_MAX_RETRY_NUMBER = 3

function shouldRetry (error, number) {
return GIT_TRANSIENT_ERROR_RE.test(error) && (number < GIT_TRANSIENT_ERROR_MAX_RETRY_NUMBER)
}

const GIT_ = 'GIT_'
Expand Down Expand Up @@ -188,7 +190,7 @@ function execGit (gitArgs, gitOpts, opts) {
opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number)
}
return execFileAsync(gitPath, gitArgs, mkOpts(gitOpts, opts)).catch((err) => {
if (shouldRetry(err)) {
if (shouldRetry(err, number)) {
retry(err)
} else {
throw err
Expand Down Expand Up @@ -219,7 +221,7 @@ function spawnGit (gitArgs, gitOpts, opts) {
child.stderr.on('data', d => { stderr += d })

return finished(child, true).catch(err => {
if (shouldRetry(stderr)) {
if (shouldRetry(stderr, number)) {
retry(err)
} else {
err.stderr = stderr
Expand Down

0 comments on commit 8bbd051

Please sign in to comment.