go
timeout_error
ai_generated
partial
context deadline exceeded
ID: go/context-deadline-exceeded
82%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
| 121 | active | — | — | — |
Root Cause
Operation timed out via context.WithTimeout/WithDeadline. Server call or DB query took too long.
genericWorkarounds
-
90% success Increase timeout to a reasonable value based on expected operation time
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
-
88% success Investigate why the operation is slow: check DB queries, network latency, etc.
check DB queries, network latency, etc
Sources: https://pkg.go.dev/context
-
80% success Add retry logic for transient timeouts
for attempt := 0; attempt < 3; attempt++ { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) err := doWork(ctx) cancel() if err == nil { break } time.Sleep(time.Duration(attempt+1) * 100 * time.Millisecond) }Sources: https://pkg.go.dev/context
Dead Ends
Common approaches that don't work:
-
Remove the context timeout
75% fail
Operations may hang forever without timeouts
-
Set a very large timeout
60% fail
Just delays the inevitable — find why the operation is slow
Error Chain
Frequently confused with: