net/http: client fails when server closes connection before reading request body #51109
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (go1.18beta2)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/QW2sddZp7XY
tl;dr: when a server sends a response and closes the connection before reading the request body, net/http fails with an error. We've observed this behavior with haproxy, and it appears to be allowed by RFC 7230:
and
What did you expect to see?
Successful HTTP response (307 Redirect)
The client should, on noting that it cannot write to the connection, check whether the data received on the connection constitutes a valid response, and if so return that response instead of an error.
What did you see instead?
Looking at a packet dump of this behavior, it appears that when the server closes the socket, the client continues sending data, which generates RST frames from the server, which translate into the given error. In fact, this all occurs before the server sends a FIN frame.
The text was updated successfully, but these errors were encountered: