# 不可用：gRPC 服务器因最大并发流限制（100）拒绝流

- **ID:** `grpc/max-concurrent-streams-server`
- **领域:** grpc
- **类别:** resource_error
- **错误码:** `GRPC_MAX_CONCURRENT_STREAMS`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

服务器已达到配置的最大并发流数（例如 100），新流请求被拒绝，直到现有流完成。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.52.x | active | — | — |
| gRPC v1.60.x | active | — | — |
| gRPC v1.65.x | active | — | — |

## 解决方案

1. ```
   增加服务器最大并发流数：设置 `GRPC_ARG_HTTP2_MAX_STREAMS` 为更高值（如 500）。在 Python 中：`grpc.server(..., options=[('grpc.max_concurrent_streams', 500)])`。
   ```
2. ```
   实现客户端连接池：创建多个 gRPC 通道（如 3-5 个），将流分布到不同通道，避免单个通道达到限制。
   ```
3. ```
   使用负载均衡器（如 Envoy）将流分发到多个服务器实例，有效增加总流容量。
   ```

## 无效尝试

- **** — Retries will still be rejected as long as the server is at capacity; it only adds latency without solving the bottleneck. (75% 失败率)
- **** — Keepalive pings do not affect stream limits; they only maintain connection health. (60% 失败率)
- **** — This setting controls the client's advertised limit, not the server's; the server independently enforces its own limit. (70% 失败率)
