Merge pull request #11998 from dmcgowan/avoid-unconditional-range-fetch

Fix fetch always adding range to requests
This commit is contained in:
Derek McGowan
2025-06-19 22:03:46 +08:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -442,7 +442,7 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
chunkSize := int64(r.performances.ConcurrentLayerFetchBuffer)
parallelism := int64(r.performances.MaxConcurrentDownloads)
if chunkSize < minChunkSize {
if chunkSize < minChunkSize || req.body != nil {
parallelism = 1
}
log.G(ctx).WithField("initial_parallelism", r.performances.MaxConcurrentDownloads).
@@ -452,7 +452,9 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
Debug("fetching layer")
req.setMediaType(mediatype)
req.header.Set("Accept-Encoding", "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5")
req.setOffset(offset)
if parallelism > 1 || offset > 0 {
req.setOffset(offset)
}
if err := r.Acquire(ctx, 1); err != nil {
return nil, err
@@ -478,7 +480,7 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
})
remaining, _ := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 0)
if parallelism > 1 && req.body == nil {
if parallelism > 1 {
// If we have a content length, we can use multiple requests to fetch
// the content in parallel. This will make download of bigger bodies
// faster, at the cost of parallelism more requests and max

View File

@@ -50,6 +50,10 @@ func TestFetcherOpen(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if start > 0 {
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
} else if r.Header.Get("Range") == "bytes=0-" {
// Simulate registries which do not support range requests
rw.WriteHeader(http.StatusBadRequest)
return
}
rw.Header().Set("content-length", strconv.Itoa(len(content[start:])))
_, _ = rw.Write(content[start:])