Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob fetch should not attempt range request by default #368

Closed
shizhMSFT opened this issue Dec 2, 2022 · 0 comments · Fixed by #369
Closed

Blob fetch should not attempt range request by default #368

shizhMSFT opened this issue Dec 2, 2022 · 0 comments · Fixed by #369
Labels
bug Something isn't working
Milestone

Comments

@shizhMSFT
Copy link
Contributor

oras-go always attempts Range header to seekable http client, which is aggressive.

func (s *blobStore) Fetch(ctx context.Context, target ocispec.Descriptor) (rc io.ReadCloser, err error) {
ref := s.repo.Reference
ref.Reference = target.Digest.String()
ctx = registryutil.WithScopeHint(ctx, ref, auth.ActionPull)
url := buildRepositoryBlobURL(s.repo.PlainHTTP, ref)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
// probe server range request ability.
// Docker spec allows range header form of "Range: bytes=<start>-<end>".
// However, the remote server may still not RFC 7233 compliant.
// Reference: https://docs.docker.com/registry/spec/api/#blob
if target.Size > 0 {
req.Header.Set("Range", fmt.Sprintf("bytes=0-%d", target.Size-1))
}
resp, err := s.repo.client().Do(req)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
resp.Body.Close()
}
}()
switch resp.StatusCode {
case http.StatusOK: // server does not support seek as `Range` was ignored.
if size := resp.ContentLength; size != -1 && size != target.Size {
return nil, fmt.Errorf("%s %q: mismatch Content-Length", resp.Request.Method, resp.Request.URL)
}
return resp.Body, nil
case http.StatusPartialContent:
return httputil.NewReadSeekCloser(s.repo.client(), req, resp.Body, target.Size), nil
case http.StatusNotFound:
return nil, fmt.Errorf("%s: %w", target.Digest, errdef.ErrNotFound)
default:
return nil, errutil.ParseErrorResponse(resp)
}
}

The Docker spec states that

This endpoint may also support RFC7233 compliant range requests. Support can be detected by issuing a HEAD request. If the header Accept-Range: bytes is returned, range requests can be used to fetch partial content.

Therefore, oras-go should do normal request by default and attempt range request only if the server explicitly states it support range query in order to be compatible with most registries with best effort.

Known impacted registry provider:

  • jFrog Artifactory
@shizhMSFT shizhMSFT added the bug Something isn't working label Dec 2, 2022
@shizhMSFT shizhMSFT added this to the v2.0.0-rc.6 milestone Dec 2, 2022
@shizhMSFT shizhMSFT moved this to Done in ORAS-Planning Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant