# grpc::RESOURCE_EXHAUSTED: gRPC 调用失败，状态码 8

- **ID:** `communication/grpc-resource-exhausted`
- **领域:** communication
- **类别:** resource_error
- **错误码:** `8`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

gRPC 服务器或客户端耗尽了内存、文件描述符或并发流限制，通常是由于流泄漏或传输层资源配额不足导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC 1.62 | active | — | — |
| gRPC-go v1.65 | active | — | — |
| gRPC-java 1.64 | active | — | — |
| envoy 1.30 | active | — | — |

## 解决方案

1. ```
   Increase the gRPC server's maximum concurrent streams: set `GRPC_ARG_MAX_CONCURRENT_STREAMS` to a higher value (e.g., 1000) and restart the server. Also monitor `grpc.server.streams` metric.
   ```
2. ```
   Add client-side connection pooling: reuse gRPC channels and limit the number of concurrent calls per channel using a semaphore or rate limiter.
   ```
3. ```
   Configure Envoy proxy to set `max_requests_per_connection` and `circuit_breakers` limits to prevent client-side resource exhaustion from overwhelming the gRPC server.
   ```

## 无效尝试

- **Increase server memory and restart** — The issue is often not raw memory but stream limit exhaustion (e.g., MAX_CONCURRENT_STREAMS). More memory doesn't increase stream quotas. (70% 失败率)
- **Set grpc.max_receive_message_size to a very high value (e.g., 500MB)** — This error is about connection-level resources, not message size. Changing message size doesn't address stream or FD exhaustion. (90% 失败率)
- **Disable keepalive pings in gRPC client** — Keepalive pings help detect dead connections and actually reduce resource leaks. Disabling them makes the problem worse. (80% 失败率)
