go
runtime_error
ai_generated
true
error: context 超时(goroutine worker)
error: context deadline exceeded (goroutine worker)
ID: go/context-deadline-exceeded-worker
80%修复率
86%置信度
0证据数
2024-12-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
带截止时间的 ctx 在 worker 完成前过期,通常因为截止时间过短或下游调用过慢。
English
A ctx with a deadline expired before the worker finished, often because the deadline was too short or a downstream call is slow.
解决方案
-
90% 成功率
Measure p99 latency and set deadline accordingly; propagate ctx everywhere: ctx, cancel := context.WithTimeout(parent, 5*time.Second) defer cancel()
-
85% 成功率
Add retries with exponential backoff for transient downstream timeouts.
无效尝试
常见但无效的做法:
-
80% 失败
Eliminates the safety net; slow calls can hang the goroutine indefinitely.
-
70% 失败
Arbitrary; if the downstream is genuinely slow, it still times out and the root latency issue remains.