go
network_error
ai_generated
true
rpc 错误:代码 = DeadlineExceeded 描述 = 上下文超过截止时间
rpc error: code = DeadlineExceeded desc = context deadline exceeded
ID: go/grpc-deadline-exceeded-context
80%修复率
88%置信度
0证据数
2024-03-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| google.golang.org/grpc v1.40+ | active | — | — | — |
根因分析
在 RPC 完成前,客户端或服务端的上下文截止时间已到。常见于服务端处理缓慢、网络拥塞,或相对于处理逻辑而言截止时间设置过短。
English
The client-side or server-side context deadline elapsed before the RPC completed. Common when the server is slow, the network is congested, or the deadline is set too aggressively relative to the handler's work.
解决方案
-
85% 成功率
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() resp, err := client.Do(ctx, req) if status.Code(err) == codes.DeadlineExceeded { // retry with backoff } -
80% 成功率
// measure handler latency, then set client deadline > p99 ctx, cancel := context.WithTimeout(ctx, p99Latency*2) defer cancel()
无效尝试
常见但无效的做法:
-
80% 失败
If the server is genuinely overloaded, tight retries amplify load and worsen latency, causing more timeouts. No jitter means thundering herd.
-
75% 失败
Unbounded calls leak goroutines and hold connections indefinitely when the server hangs, eventually exhausting resources.