Default Go http.Transport settings that bite under bursty fan-out
http.DefaultTransport in Go is tuned for talking to many different hosts, not hammering a single internal backend. Its MaxIdleConnsPerHost defaults to 2.
What happens during a burst
When a handler fans out 40 concurrent HTTP/1.1 requests to the same upstream service, Go opens 40 TCP connections. As soon as the burst finishes, 38 of those connections are closed immediately instead of returned to the idle pool. On the next burst milliseconds later, the process pays 38 fresh TCP + TLS handshakes and piles up thousands of TIME_WAIT sockets.
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.MaxIdleConns = 256
tr.MaxIdleConnsPerHost = 64
tr.IdleConnTimeout = 90 * time.Second
client := &http.Client{Transport: tr, Timeout: 10 * time.Second}
Do not forget response bodies
Even with a larger idle pool, a connection cannot be reused unless the caller both drains and closes resp.Body. A single missed io.Copy(io.Discard, resp.Body) on an error path silently turns keep-alive back into one-shot connections.