blob: f184ad84c14fcfd583ccab6d9a78b58e8d83671d [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
// defaultGitRetry is the set of RE2-formatted Regular Expressions to add
// to the DefaultGitRetryRegexp.
// defaultGitRetryPOSIX was originally translated from "chromite":
var defaultGitRetryRegexpSource = []string{
`!.*\[remote rejected\].*\(error in hook\)`,
`!.*\[remote rejected\].*\(failed to lock\)`,
`!.*\[remote rejected\].*\(error in Gerrit backend\)`,
`remote error: Internal Server Error`,
`fatal: Couldn't find remote ref `,
`git fetch_pack: expected ACK/NAK, got`,
`protocol error: bad pack header`,
`The remote end hung up unexpectedly`,
`The remote end hung up upon initial contact`,
`TLS packet with unexpected length was received`,
`RPC failed; result=\d+, HTTP code = \d+`,
`Connection timed out`,
//, b/19202011
`repository cannot accept new pushes; contact support`,
`Service Temporarily Unavailable`,
`The service is currently unavailable`,
`Connection refused`,
`The requested URL returned error: 5\d+`,
`Operation too slow`,
`Connection reset by peer`,
`Unable to look up`,
`Couldn't resolve host`,
`Unknown SSL protocol error`,
// b/110032771
`Revision .* of patch set \d+ does not match refs/changes`,
// &
`Git repository not found`,
`Couldn't connect to server`,
`transfer closed with outstanding read data remaining`,
`Access denied to`,
`The requested URL returned error: 429`,
// b/155578399
`Resource has been exhausted`,
`check quota`,
// b/158498614
`fetch-pack: protocol error: bad band #\d+`,
// b/170222146
`The requested URL returned error: 400`,
`fetch-pack: fetch failed`,
`fetch-pack: unable to spawn http-fetch`,
`fetch-pack: expected keep then TAB at start of http-fetch output`,
`fetch-pack: expected hash then LF at end of http-fetch output`,
`fetch-pack: unable to finish http-fetch`,
`fetch-pack: pack downloaded from .* does not match expected hash .*`,
// DefaultGitRetryRegexp is the set of default transient regular expressions to
// retry on.
var DefaultGitRetryRegexp *regexp.Regexp
func init() {
if len(defaultGitRetryRegexpSource) > 0 {
DefaultGitRetryRegexp = regexp.MustCompile(mergeRegex(defaultGitRetryRegexpSource))
// mergeRegex merges multiple regular expression strings together into a single
// "|"-delimited regular expression group. No capture groups are introduced in
// this merge.
func mergeRegex(regexps []string) string {
// Merge all of the regex into a single regex.
allRE := make([]string, len(regexps))
for i, re := range regexps {
allRE[i] = "(?:" + re + ")"
return "(?i)(?:" + strings.Join(allRE, "|") + ")"