# DEADLINE_EXCEEDED: grpc: 等待服务器响应 5000ms 后超时

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

## 根因

服务器响应时间超过客户端截止时间，通常是由于服务器过载或处理缓慢。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.44.0 | active | — | — |
| gRPC v1.51.0 | active | — | — |
| gRPC v1.59.0 | active | — | — |

## 解决方案

1. ```
   Profile the server to identify slow operations (e.g., database queries, external API calls). Use tools like pprof or tracing. Example in Go: go tool pprof http://localhost:6060/debug/pprof/profile
   ```
2. ```
   Implement server-side rate limiting or request queuing to handle load spikes. Use a circuit breaker pattern to reject requests when the server is overloaded.
   ```
3. ```
   Increase the client deadline to a reasonable value (e.g., 10 seconds) and add retry with exponential backoff. Example in Python with grpc.aio: await asyncio.wait_for(stub.MyRpc(request), timeout=10)
   ```

## 无效尝试

- **** — This masks the problem but doesn't fix server performance; long deadlines can cause resource leaks. (60% 失败率)
- **** — The underlying performance issue (e.g., slow database queries) will reappear after restart. (75% 失败率)
- **** — Repeated retries can overwhelm the server further, worsening the problem. (80% 失败率)
