Repository navigation
blob/s3blob, blob/azureblob: close the response body on zero-length reads - #3850
Merged
Merged
Conversation
…eads For a zero-length read, NewRangeReader replaced the response body with http.NoBody but never closed the real one, so each zero-length read kept an HTTP connection open. Close it before replacing it.
iamabhilaksh
marked this pull request as ready for review
November 16, 2026 12:18
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3850 +/- ##
==========================================
+ Coverage 80.35% 80.94% +0.59%
==========================================
Files 104 104
Lines 12571 12620 +49
==========================================
+ Hits 10101 10215 +114
+ Misses 2469 2404 -65
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
On a zero-length read,
NewRangeReaderreplaces the response body withhttp.NoBodyand never closes the real body (s3blob.go#L669-L672, azureblob.go#L703-L708).Reader.Closethen closes onlyhttp.NoBody, so each zero-length read leaves an HTTP connection open.Change
TestZeroLengthReadClosesBodyin each package. It expects 1 body closed.Impact and risk
Closeon a body that was already discarded. The data returned doesn't change.Close. Go 1.27 doesn't fix master, since it only drains bodies that are closed.Testing
30 zero-length reads of a 1 MiB object, then
Close:closed 0 response bodies, want 1.Checks (go1.27.3 and go1.26.10):
go test -race,go vet,gofmt -sand golangci-lint v2.14.0 pass.go.modand alldeps are unchanged.Not changed here: azureblob still requests the whole blob, because
Count: 0means no limit. Requesting a range on an empty blob might fail with 416.