Go 1.27 improves HTTP/1 connection reuse performance
Key Takeaway
Go 1.27 significantly reduces the cost of unread HTTP/1 response bodies by improving connection reuse mechanics.
Summary
The Go programming language's net/http package has seen a major performance boost in Go 1.27 regarding HTTP/1 connection reuse. Previously, in Go 1.26 and earlier, failing to fully read an HTTP/1 response body caused the client to abandon the TCP connection, forcing a new handshake for subsequent requests. Go 1.27 addresses this, resulting in up to a fivefold speed increase in specific benchmarks.
Solving the unread body problem
- In HTTP/1, responses are sent sequentially; the client cannot find the start of the next response until the current body is fully consumed.
- Prior to Go 1.27, calling
resp.Body.Close()on an unread body causednet/httpto discard the connection. - This issue often occurred when using
encoding/json.Decoder, which may leave trailing bytes like newlines unread. - Benchmarks show 100 requests to
index.golang.orgdropped from ~710ms in Go 1.26 to ~150ms in Go 1.27 when using HTTP/1.
Why it matters
This change prevents silent performance degradation in Go applications that interact with APIs without fully consuming response bodies.
Original reference: go.dev →