upload: fix PUT retry

This commit is contained in:
Michael Yang 2023-11-29 15:18:53 -08:00
parent c4bdfffd96
commit 13efd5f218

View file

@ -194,24 +194,22 @@ func (b *blobUpload) Run(ctx context.Context, opts *RegistryOptions) {
headers.Set("Content-Length", "0") headers.Set("Content-Length", "0")
for try := 0; try < maxRetries; try++ { for try := 0; try < maxRetries; try++ {
resp, err := makeRequestWithRetry(ctx, http.MethodPut, requestURL, headers, nil, opts) var resp *http.Response
if err != nil { resp, err = makeRequestWithRetry(ctx, http.MethodPut, requestURL, headers, nil, opts)
b.err = err if errors.Is(err, context.Canceled) {
if errors.Is(err, context.Canceled) { break
return } else if err != nil {
}
sleep := time.Second * time.Duration(math.Pow(2, float64(try))) sleep := time.Second * time.Duration(math.Pow(2, float64(try)))
log.Printf("%s complete upload attempt %d failed: %v, retrying in %s", b.Digest[7:19], try, err, sleep) log.Printf("%s complete upload attempt %d failed: %v, retrying in %s", b.Digest[7:19], try, err, sleep)
time.Sleep(sleep) time.Sleep(sleep)
continue continue
} }
defer resp.Body.Close() defer resp.Body.Close()
break
b.err = nil
b.done = true
return
} }
b.err = err
b.done = true
} }
func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *url.URL, part *blobUploadPart, opts *RegistryOptions) error { func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *url.URL, part *blobUploadPart, opts *RegistryOptions) error {