Resume chunk download on UnexpectedEOF errors

If the chunk download is interrupted, resume from where we left off
This commit is contained in:
Daniel Hiltgen 2023-11-08 13:24:11 -08:00
parent c819d7f68a
commit cc54a416c6

View file

@ -161,6 +161,9 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
log.Printf("%s part %d attempt %d failed: %v, retrying", b.Digest[7:19], i, try, err) log.Printf("%s part %d attempt %d failed: %v, retrying", b.Digest[7:19], i, try, err)
continue continue
default: default:
if try > 0 {
log.Printf("%s part %d completed after %d retries", b.Digest[7:19], i, try)
}
return nil return nil
} }
} }
@ -202,7 +205,7 @@ func (b *blobDownload) downloadChunk(ctx context.Context, requestURL *url.URL, w
defer resp.Body.Close() defer resp.Body.Close()
n, err := io.Copy(w, io.TeeReader(resp.Body, b)) n, err := io.Copy(w, io.TeeReader(resp.Body, b))
if err != nil && !errors.Is(err, context.Canceled) { if err != nil && !errors.Is(err, context.Canceled) && !errors.Is(err, io.ErrUnexpectedEOF) {
// rollback progress // rollback progress
b.Completed.Add(-n) b.Completed.Add(-n)
return err return err
@ -213,7 +216,7 @@ func (b *blobDownload) downloadChunk(ctx context.Context, requestURL *url.URL, w
return err return err
} }
// return nil or context.Canceled // return nil or context.Canceled or UnexpectedEOF (resumable)
return err return err
} }