fix: Set GetBody on uploads for HTTP/2 retry#4318
Merged
Merged
Conversation
NewUploadRequest passed a body to http.NewRequestWithContext without setting Request.GetBody, so net/http2 could not rewind the body and failed asset uploads with "cannot retry ... after Request.Body was written" when a stream was refused (REFUSED_STREAM/GOAWAY). Set GetBody when the reader implements both io.Seeker (to capture the body's starting offset) and io.ReaderAt, returning an independent io.SectionReader so GetBody yields a fresh copy without disturbing the original body's read position. Readers that cannot provide an independent, rewindable view are left without GetBody to avoid buffering large uploads in memory. Fixes google#2113
GetBody on uploads for HTTP/2 retry
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4318 +/- ##
=======================================
Coverage 97.47% 97.47%
=======================================
Files 192 192
Lines 19312 19320 +8
=======================================
+ Hits 18824 18832 +8
Misses 270 270
Partials 218 218 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmlewis
requested changes
Jun 22, 2026
gmlewis
left a comment
Collaborator
There was a problem hiding this comment.
Thank you, @JamBalaya56562!
Pass a closed *os.File (via openTestFile) to NewUploadRequest so the io.SeekCurrent probe fails, covering the previously untested error branch that returns the seek error.
gmlewis
approved these changes
Jun 22, 2026
gmlewis
left a comment
Collaborator
There was a problem hiding this comment.
Excellent. Thank you, @JamBalaya56562!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
Collaborator
|
Thank you, @stevehipwell! |
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.
Fixes #2113
Problem
NewUploadRequestpassed the body tohttp.NewRequestWithContextwithout settingRequest.GetBody. Unlike the JSONNewRequestpath (where the Go stdlib auto-populatesGetBodyfor*bytes.Buffer), the upload path wraps the reader inuploadRequestBodyReaderto hide concrete types, soGetBodystayed nil. As a resultnet/http2could not rewind the body and asset uploads failed with:when a stream was refused (REFUSED_STREAM / GOAWAY / idle-connection close). This has been reported by several downstream tools (ghr, goreleaser, go-release-action).
Fix
Set
req.GetBodywhen the reader implements bothio.Seeker(to record the body's starting offset) andio.ReaderAt.GetBodyreturns an independentio.SectionReader(re-wrapped inuploadRequestBodyReaderto preserve the existing race-safety behaviour), so each call yields a fresh copy without disturbing the original body's read position — honoring thehttp.Request.GetBodycontract.This is satisfied by
*os.File(used byUploadReleaseAsset),*bytes.Readerand*strings.Reader. Readers that cannot provide an independent, rewindable view are intentionally left withoutGetBodyso large uploads are never buffered in memory.This is a backwards-compatible change (no signature changes).
Tests
TestNewUploadRequest_setsGetBodyForSeekableReader— assertsGetBodyis set, returns identical bytes on repeated calls, and does not consume the originalreq.Body.TestNewUploadRequest_noGetBodyWithoutReaderAt— assertsGetBodystays nil for a non-seekable reader and for a seek-only reader withoutio.ReaderAt.go test -race ./github/,go vet, and golangci-lint all pass.