From 2229535e7e71669779589536cf0a842b46a7ee38 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Wed, 10 May 2023 16:04:04 +0200 Subject: [PATCH] Retry fetching Bazel versions from GCS URL (#459) * Retry fetching GCS URL * Sleep --- repositories/gcs.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/repositories/gcs.go b/repositories/gcs.go index 542e781d..db6f0b8f 100644 --- a/repositories/gcs.go +++ b/repositories/gcs.go @@ -9,6 +9,7 @@ import ( "fmt" "log" "strings" + "time" "github.com/bazelbuild/bazelisk/core" "github.com/bazelbuild/bazelisk/httputil" @@ -77,7 +78,22 @@ func listDirectoriesInReleaseBucket(prefix string) ([]string, bool, error) { if nextPageToken != "" { url = fmt.Sprintf("%s&pageToken=%s", baseURL, nextPageToken) } - content, _, err := httputil.ReadRemoteFile(url, "") + + var content []byte + var err error + // Theoretically, this should always work, but we've seen transient + // errors on Bazel CI, so we retry a few times to work around this. + // https://github.com/bazelbuild/continuous-integration/issues/1627 + waitTime := 100 * time.Microsecond + for attempt := 0; attempt < 5; attempt++ { + content, _, err = httputil.ReadRemoteFile(url, "") + if err == nil { + break + } + time.Sleep(waitTime) + waitTime *= 2 + } + if err != nil { return nil, false, fmt.Errorf("could not list GCS objects at %s: %v", url, err) }