Skip to content

Commit

Permalink
Retry fetching Bazel versions from GCS URL (#459)
Browse files Browse the repository at this point in the history
* Retry fetching GCS URL

* Sleep
  • Loading branch information
meteorcloudy authored May 10, 2023
1 parent 0d390e8 commit 2229535
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion repositories/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/bazelbuild/bazelisk/core"
"github.com/bazelbuild/bazelisk/httputil"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2229535

Please sign in to comment.