# rpc 错误：code = DeadlineExceeded，desc = 上下文截止时间已超过

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

## 根因

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

## 版本兼容性

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

## 解决方案

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.
   ```

## 无效尝试

- **** — Removes the safety net; hung servers block callers forever and exhaust connection pools. (70% 失败率)
- **** — Without jitter/backoff, retries amplify load on an already-slow server, causing cascading timeouts. (75% 失败率)
