go
network_error
ai_generated
true
rpc 错误:code = DeadlineExceeded desc = 上下文截止时间已超过
rpc error: code = DeadlineExceeded desc = context deadline exceeded
ID: go/grpc-deadline-exceeded
80%修复率
87%置信度
0证据数
2024-02-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.x | active | — | — | — |
根因分析
RPC 的上下文截止时间在服务端返回响应前已耗尽。常见原因:服务端处理慢于截止时间、网络延迟,或下游依赖阻塞了处理函数。
English
The RPC's context deadline elapsed before the server returned a response. Common causes: server-side processing slower than the deadline, network latency, or a downstream dependency blocking the handler.
解决方案
-
90% 成功率
Propagate the incoming context deadline to downstream calls and add a per-call timeout: ctx, cancel := context.WithTimeout(ctx, 2*time.Second); defer cancel(); resp, err := client.Do(ctx, req).
-
82% 成功率
Instrument server handlers with grpc.UnaryInterceptor to log elapsed time per method and identify slow handlers, then optimize or move work to a background queue.
无效尝试
常见但无效的做法:
-
75% 失败
Without a deadline, a hung server leaks goroutines and connections, eventually exhausting resources and causing cascading failures.
-
70% 失败
A uniformly huge deadline defeats the purpose of cancellation and still fails if the server is genuinely stuck; it also delays failure detection.