go runtime_error ai_generated partial

rpc 错误:code = DeadlineExceeded,desc = 上下文截止时间已超过

rpc error: code = DeadlineExceeded desc = context deadline exceeded

ID: go/grpc-deadline-exceeded-server

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-02-08首次发现

版本兼容性

版本状态引入弃用备注
google.golang.org/grpc 1.40+ active — — —

根因分析

客户端上下文截止时间在服务端响应前已耗尽;服务端可能仍在处理,或网络较慢。

English

The client-side context deadline elapsed before the server responded; the server may still be processing, or the network is slow.

generic

解决方案

  1. 90% 成功率
    Propagate deadlines from the caller and add per-RPC timeout at the client:
    ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
    defer cancel()
    resp, err := client.Get(ctx, req)
  2. 85% 成功率
    Instrument server-side handler duration (otelgrpc / prometheus) to distinguish slow processing from network latency, then tune deadline accordingly.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Removes the safety net; hung servers block callers forever and exhaust connection pools.

  2. 75% 失败

    Without jitter/backoff, retries amplify load on an already-slow server, causing cascading timeouts.