
Clean Socket: How Go Learned to Reuse HTTP/1 Connections Efficiently
For years, the familiar defer resp.Body.Close() call in Go hid a subtle architectural trap. If an application closed a connection without draining the response body all the way to io.EOF, net/http marked the socket as "dirty." Leaving just a single unread byte in the buffer—such as a newline after JSON decoding—forced the runtime to tear down the TCP session and pay for fresh TLS handshakes.
In Go 1.27, engineers introduced a smart asynchronous background drain (up to 256 KB within 50 ms), cutting the execution time of request batches nearly fivefold. Here is how socket transport internals work and how to tune your connection pool.
