Repository navigation
fix(proxy): keep blob headers off early error responses - #5115
Merged
milosgajdos merged 1 commit intoNov 28, 2026
Merged
Conversation
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]>
justincormack
approved these changes
Nov 28, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The proxy used to set
Content-Lengthas 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 withContent-Lengthstill set to 4,096. The client read the entire error and still reported an unexpectedEOF. 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.