Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

fix(git): limit retry times, avoid unlimited retry make npm install process will never end #172

Merged
merged 1 commit into from Jun 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/util/git.js
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