go
network_error
ai_generated
true
error: context deadline exceeded (from select ctx.Done())
ID: go/context-deadline-exceeded-in-select
80%Fix Rate
88%Confidence
0Evidence
2024-08-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.7+ | active | — | — | — |
Root Cause
A select statement observes ctx.Done() because the parent context's deadline elapsed. The downstream operation is cancelled, but the caller treats it as a generic error.
generic中文
select 语句观察到 ctx.Done(),因为父上下文的截止时间已到。下游操作被取消,但调用方将其视为通用错误。
Workarounds
-
96% success
select { case <-ctx.Done(): return ctx.Err() case res := <-ch: return res } -
90% success
for i := 0; i < 3; i++ { ctx, cancel := context.WithTimeout(parent, 2*time.Second) err := call(ctx) cancel() if err == nil { return nil } }
Dead Ends
Common approaches that don't work:
-
95% fail
The deadline is fixed; every retry burns the same expired context and returns instantly.
-
90% fail
Callers receive silently wrong results and downstream logic corrupts data.