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

- **ID:** `go/grpc-deadline-exceeded-long-running`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

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) }
   ```

## 无效尝试

- **** — This may hide the underlying performance issue and cause long hangs. (40% 失败率)
- **** — The server may have partially processed the request, leading to inconsistency. (90% 失败率)
