Problem Statement
The default http.DefaultClient has no timeout and poor connection pool settings. Configure a production-ready HTTP client that won't leak connections or hang forever.
The Default Client Trap
Production HTTP Client
Connection Pool Sizing
Request-Level Timeout with Context
Common Production Issues
| Issue | Cause | Fix |
|---|---|---|
| Connection leak | Not closing resp.Body | Always defer resp.Body.Close() |
| Too many TIME_WAIT | Low MaxIdleConnsPerHost | Increase to 10-100 |
| Request hangs | No timeout set | Set Client.Timeout |
| DNS stale | Cached DNS entries | Limit connection age |