in origin/blobclient/cluster_client.go [268:307]
func Poll(
r ClientResolver, b backoff.BackOff, d core.Digest, makeRequest func(Client) error) error {
// By looping over clients in order, we will always prefer the same origin
// for making requests to loosely guarantee that only one origin needs to
// fetch the file from remote backend.
clients, err := r.Resolve(d)
if err != nil {
return fmt.Errorf("resolve clients: %s", err)
}
var errs []error
ORIGINS:
for _, client := range clients {
b.Reset()
POLL:
for {
if err := makeRequest(client); err != nil {
if serr, ok := err.(httputil.StatusError); ok {
if serr.Status == http.StatusAccepted {
d := b.NextBackOff()
if d == backoff.Stop {
break POLL // Backoff timed out.
}
time.Sleep(d)
continue POLL
}
if serr.Status < 500 {
return err
}
}
errs = append(errs, fmt.Errorf("origin %s: %s", client.Addr(), err))
continue ORIGINS
}
return nil // Success!
}
errs = append(errs,
fmt.Errorf("origin %s: backoff timed out on 202 responses", client.Addr()))
}
return fmt.Errorf("all origins unavailable: %s", errutil.Join(errs))
}