context deadline exceeded Go Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Go

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

  1. Measure the call duration with logging
  2. Increase the timeout or use retries with backoff
  3. Use errors.Is(err, context.DeadlineExceeded) to branch

Detailed fix by platform

Go

  1. ctx, cancel := context.WithTimeout(ctx, 5*time.Second); defer cancel()

How to diagnose

  1. Timeout — Value vs call time?
  2. Parent — Remaining deadline?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

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' (Google Cloud / Firebase)429 RESOURCE_EXHAUSTE…assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…Client.Timeout exceeded while awaiting headers — Go: net/http: request canceled (Client.Timeout exceeded while awaiting headers) (Go)Client.Timeout exceed…Cloud Functions: Function execution took 60000 ms, finished with status: timeout — Cloud Functions: Function execution took 60002 ms, finished with status: 'timeout' (Google Cloud / Firebase)Cloud Functions: Func…context canceled — Go: context canceled (rpc error: code = Canceled desc = context canceled) (Go)context canceledcURL error 28: Operation timed out (Laravel HTTP client) — Laravel: Illuminate\Http\Client\ConnectionException: cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (Laravel)cURL error 28: Operat…dial tcp: connect: connection refused — Go: dial tcp 127.0.0.1:5432: connect: connection refused (Go)dial tcp: connect: co…context d…

Explore the map of this error Full error map →

🧠 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.