go runtime_error ai_generated true

error: context 超时(goroutine worker)

error: context deadline exceeded (goroutine worker)

ID: go/context-deadline-exceeded-worker

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 90% 成功率
    Measure p99 latency and set deadline accordingly; propagate ctx everywhere:
    
    ctx, cancel := context.WithTimeout(parent, 5*time.Second)
    defer cancel()
  2. 85% 成功率
    Add retries with exponential backoff for transient downstream timeouts.

无效尝试

常见但无效的做法:

  1. 80% 失败

    Eliminates the safety net; slow calls can hang the goroutine indefinitely.

  2. 70% 失败

    Arbitrary; if the downstream is genuinely slow, it still times out and the root latency issue remains.