Go: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
An http.Client with a Timeout gave up waiting for the server's response headers.
net/http: request canceled (Client.Timeout exceeded while awaiting headers)Client.Timeout exceeded while awaiting headersnet/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)net/http: TLS handshake timeoutClient.Timeout or context cancellation while reading body Meaning
The server was slow or hung, or the client Timeout is too short. http.Client.Timeout covers the whole exchange including body read. Use Transport settings (ResponseHeaderTimeout, DialContext) for finer control and never use the default client without a timeout in production.
Common causes
- Slow upstream API
- Timeout too short
- Network partition or DNS slowness
- Large response body reading time included
- Overloaded server behind a proxy
⚡ Quick fix
- Raise
Client.Timeoutor tuneResponseHeaderTimeout - Retry idempotent requests with backoff
- Add observability for upstream latency
Detailed fix by platform
Go
client := &http.Client{Timeout: 15 * time.Second}
How to diagnose
- Phase — Dial, headers or body?
- Value — Reasonable?
- Upstream — Slow?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- context deadline exceeded Go: Get "https://api.example.com": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
- dial tcp: connect: connection refused Go: dial tcp 127.0.0.1:5432: connect: connection refused
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026