Repository navigation
[BUGFIX] Drain deduplicated upload request bodies - #161
Merged
hferentschik merged 2 commits intoSep 22, 2026
Merged
Conversation
marchmallow
marked this pull request as ready for review
September 22, 2026 08:11
hferentschik
approved these changes
Sep 22, 2026
marchmallow
force-pushed
the
dd/fix/drain-deduplicated-upload-body-20260921
branch
from
September 22, 2026 11:31
ae41152 to
603a588
Compare
Member
Author
|
@hferentschik concern on checking size addressed but a bit more complicated than 1 line of code changes, agent rationale for it added to the PR description under "Why use a local http.MaxBytesReader?" |
hferentschik
approved these changes
Sep 22, 2026
hferentschik
deleted the
dd/fix/drain-deduplicated-upload-body-20260921
branch
September 22, 2026 12:16
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.
Motivation & Context
Connection: close; after its 500 ms reset-avoidance wait, the final close can prevent an intermediary from delivering the already-produced response headers to the client.Content-Length, and limit errors are mapped consistently across the deduplication and physical-write paths.http.MaxBytesReaderstops after observingContent-Length + 1bytes and the handler returns HTTP 413 when the error remains recoverable.Interface Changes
PUT /v2/blobs/putdeduplication behavior now requires the server to consume the declared request body before returning HTTP 200.Why use a local
http.MaxBytesReader?The handler already rejects
Content-Lengthvalues above its configured maximum. The validated declaration is therefore a tighter and more appropriate runtime read limit than the full service maximum.The wrapper is kept in a local variable and is not assigned back to
r.Body. This preserves Go 1.25's concrete request-body types sonet/httpcan retain its special early-response behavior when validation fails before the body is consumed, including requests usingExpect: 100-continue.The deduplication path drains the bounded reader and checks the copied byte count before writing HTTP 200. The physical-write path passes the same bounded reader through the checksum tee to the selected storage driver.
Why does this also change the GCS storage driver?
On a deduplication hit, the handler itself reads the bounded body and can classify
*http.MaxBytesErrordirectly. On a physical write, the storage driver consumes the supplied reader, so any limit error is returned through that driver's error chain.The GCS driver previously formatted its
io.Copyfailure with%v:That preserved only the error text and discarded the underlying error identity. Consequently, the handler's
errors.Ascheck could not recover*http.MaxBytesError, and an oversized physical write through GCS would be reported as HTTP 500 instead of HTTP 413.The GCS wrapper now uses
%w:This does not change the upload outcome: GCS still stops and returns an error. It only preserves the cause so the handler can classify body-limit failures consistently across storage backends. A small copy helper makes this behavior testable without credentials or a live GCS bucket.
Validation
Connection: close.io.ErrUnexpectedEOF, unrelated reader failures, and an overrun that reads exactly one byte beyond the declaration before returning HTTP 413.Expect: 100-continue.Risks