go network_error ai_generated true

rpc 错误:代码 = DeadlineExceeded 描述 = 上下文截止日期已超过

rpc error: code = DeadlineExceeded desc = context deadline exceeded

ID: go/grpc-deadline-exceeded-long-running

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

版本兼容性

版本状态引入弃用备注
1.x active

根因分析

客户端为 RPC 设置了截止日期(通过 context.WithTimeout 或 context.WithDeadline),但服务器响应时间超过了允许的时间。

English

The client set a deadline (via context.WithTimeout or context.WithDeadline) for the RPC, but the server took longer to respond than the allowed time.

generic

解决方案

  1. 70% 成功率
    Profile the handler and reduce database queries or external calls.
  2. 80% 成功率
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second); defer cancel(); for i := 0; i < 3; i++ { err := client.Call(ctx, ...); if err == nil { break }; time.Sleep(time.Duration(i)*time.Second) }

无效尝试

常见但无效的做法:

  1. 40% 失败

    This may hide the underlying performance issue and cause long hangs.

  2. 90% 失败

    The server may have partially processed the request, leading to inconsistency.