From d39709260f29a8a556430b9edcb0ec5c33213595 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Thu, 2 Nov 2023 13:13:32 -0700 Subject: [PATCH] download with retry --- server/download.go | 9 ++------- server/images.go | 12 +----------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/server/download.go b/server/download.go index 2ebd9737..68798afd 100644 --- a/server/download.go +++ b/server/download.go @@ -89,17 +89,12 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R } if len(b.Parts) == 0 { - resp, err := makeRequest(ctx, http.MethodHead, requestURL, nil, nil, opts) + resp, err := makeRequestWithRetry(ctx, http.MethodHead, requestURL, nil, nil, opts) if err != nil { return err } defer resp.Body.Close() - if resp.StatusCode >= http.StatusBadRequest { - body, _ := io.ReadAll(resp.Body) - return fmt.Errorf("registry responded with code %d: %v", resp.StatusCode, string(body)) - } - b.Total, _ = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64) var size = b.Total / numDownloadParts @@ -199,7 +194,7 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis func (b *blobDownload) downloadChunk(ctx context.Context, requestURL *url.URL, w io.Writer, part *blobDownloadPart, opts *RegistryOptions) error { headers := make(http.Header) headers.Set("Range", fmt.Sprintf("bytes=%d-%d", part.StartsAt(), part.StopsAt()-1)) - resp, err := makeRequest(ctx, http.MethodGet, requestURL, headers, nil, opts) + resp, err := makeRequestWithRetry(ctx, http.MethodGet, requestURL, headers, nil, opts) if err != nil { return err } diff --git a/server/images.go b/server/images.go index 358520bd..67d7eee7 100644 --- a/server/images.go +++ b/server/images.go @@ -1120,22 +1120,12 @@ func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *RegistryOptio headers := make(http.Header) headers.Set("Accept", "application/vnd.docker.distribution.manifest.v2+json") - resp, err := makeRequest(ctx, http.MethodGet, requestURL, headers, nil, regOpts) + resp, err := makeRequestWithRetry(ctx, http.MethodGet, requestURL, headers, nil, regOpts) if err != nil { - log.Printf("couldn't get manifest: %v", err) return nil, err } defer resp.Body.Close() - if resp.StatusCode >= http.StatusBadRequest { - if resp.StatusCode == http.StatusNotFound { - return nil, fmt.Errorf("model not found") - } - - body, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("on pull registry responded with code %d: %s", resp.StatusCode, body) - } - var m *ManifestV2 if err := json.NewDecoder(resp.Body).Decode(&m); err != nil { return nil, err