Repository navigation
transport/http: return nil from WriteTo on a closed body - #752
Open
AzarudeenshariffA wants to merge 1 commit into
Open
AzarudeenshariffA wants to merge 1 commit into
AzarudeenshariffA wants to merge 1 commit into
Conversation
safeWriteToReadCloser.WriteTo returned io.EOF after Close. io.WriterTo has no end-of-stream error, so io.Copy passes it on as a failure. net/http's extra-bytes check on a request body (io.Copy(io.Discard, body)) can run after the SDK has closed the body, and the io.EOF then makes net/http close the connection while the response is still being read. Fixes aws#751
AzarudeenshariffA
force-pushed
the
fix-writeto-eof-after-close
branch
from
November 14, 2026 14:06
3c70b67 to
af40147
Compare
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 #751.
safeWriteToReadCloser.WriteToreturnedio.EOFonce the body was closed.io.WriterTohas no end-of-stream error, soio.Copyhands thatio.EOFback to its caller as a failure.net/http checks a request body for extra bytes with
io.Copy(io.Discard, body). That check can run afterclient.Dohas returned and the SDK has closed the body. When it does, theio.EOFmakesRequest.writefail and the connection gets closed under a response that's still being read. The issue has the details and how we reproduced it.This change returns
(0, nil)fromWriteToafterClose. That's whatio.Copywould end up with if it read throughReadinstead.Tests: the existing
TestNewSafeReadCloser_WriteTocase now expects a nil error afterClose, and there's a new case that runsio.Copy(io.Discard, body)on a closed body and expects it to succeed. I haven't run the test suite locally; I'm relying on CI here.Changelog entry added under
.changelog/.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.