Skip to content

fix(proxy): keep blob headers off early error responses - #5115

Merged
milosgajdos merged 1 commit into
distribution:mainfrom
milosgajdos:fix/proxy-blob-error-headers
Nov 28, 2026
Merged

milosgajdos merged 1 commit into
distribution:mainfrom
milosgajdos:fix/proxy-blob-error-headers

Conversation

@milosgajdos

Copy link
Copy Markdown
Member

The proxy used to set Content-Length as soon as it knew the blob size. If the upstream promised 4,096 bytes and then sent none, the registry sent a short JSON error with Content-Length still set to 4,096. The client read the entire error and still reported an unexpected EOF. SADNESS.

This PR sets the blob headers just before writing the first bytes to the client. An empty blob has no first write, so we set its headers only after any cache work succeeds. If the read or the cache commit fails before then, the registry can send the JSON error with its own headers.

The proxy used to set Content-Length as soon as it knew the blob size.
If the upstream promised 4,096 bytes and then sent none, the registry
sent a short JSON error with Content-Length still set to 4,096. The
client read the entire error and still reported an unexpected EOF.

Set the blob headers just before writing the first bytes to the client.
An empty blob has no first write, so set its headers only after any
cache work succeeds. If the read or the cache commit fails before then,
the registry can send the JSON error with its own headers.

Signed-off-by: Milos Gajdos <[email protected]>
@github-actions github-actions Bot added area/proxy Related to registry as a pull-through cache area/api labels Nov 27, 2026
@milosgajdos
milosgajdos merged commit 30db6f4 into distribution:main Nov 28, 2026
25 checks passed
jgehrcke added a commit to jgehrcke/distribution that referenced this pull request Nov 28, 2026
This test confirms that the proxy uses the response writer's Write
method when a request misses the cache for a blob already being fetched.

In distribution#5052 the registry's response writer forwards ReadFrom to enable
sendfile. Without blobResponseWriter from distribution#5115, io.CopyN would use
ReadFrom here. With Prometheus instrumentation enabled, promhttp's
ReadFrom would commit status 200 before reading the upstream body,
even if the first read failed (prometheus/client_golang#2155).

Using Write here costs us no sendfile opportunity. ReadFrom would still
read the upstream HTTP response body through an HTTPReadSeeker.

Keep blobResponseWriter and this test after upgrading to a client_golang
release that fixes distribution#2155. The wrapper sets blob headers on the first
write of blob data, so early error responses keep their own headers.

Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api area/proxy Related to registry as a pull-through cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants