Go: Get "https://api.example.com": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
An operation did not finish before its context deadline or HTTP client timeout.
context deadline exceededGet "https://api.example.com": context deadline exceededcontext deadline exceeded (Client.Timeout exceeded while awaiting headers)rpc error: code = DeadlineExceeded desc = context deadline exceeded Meaning
The remote service was slow, unreachable or your timeout is too small. Retry with backoff, raise the timeout where justified, add per-stage timeouts, and make sure the context is not shared with other long-running work. context.DeadlineExceeded can be tested with errors.Is.
Common causes
- Remote service slow or hanging
- Timeout shorter than operation needs
- Parent context already near its deadline
- Database or network congestion
- DNS delays
⚡ Quick fix
- Measure the call duration with logging
- Increase the timeout or use retries with backoff
- Use
errors.Is(err, context.DeadlineExceeded)to branch
Detailed fix by platform
Go
ctx, cancel := context.WithTimeout(ctx, 5*time.Second); defer cancel()
How to diagnose
- Timeout — Value vs call time?
- Parent — Remaining deadline?
- Remote — Healthy?
🔧 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
- 429 RESOURCE_EXHAUSTED: Quota exceeded for quota metric Google API: 429 RESOURCE_EXHAUSTED — Quota exceeded for quota metric 'Read requests' and limit 'Read requests per minute per user'
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
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