# INTERNAL: grpc: 由于服务器最大并发流限制 (128)，流创建失败

- **ID:** `grpc/stream-creation-failure-max-streams`
- **领域:** grpc
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

gRPC 服务器达到了配置的最大并发流数（默认 100 或 128），拒绝创建新流。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC C++ 1.63.0 | active | — | — |
| gRPC Java 1.61.0 | active | — | — |
| gRPC Python 1.64.0 | active | — | — |

## 解决方案

1. ```
   在服务器端增加 `GRPC_ARG_HTTP2_MAX_CONCURRENT_STREAMS` 到更高值（如 256）：`server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options=[('grpc.max_concurrent_streams', 256)])`
   ```
2. ```
   实现客户端连接池以复用流：`channel = grpc.insecure_channel('localhost:50051', options=[('grpc.use_local_subchannel_pool', 1)])`
   ```

## 无效尝试

- **Increase max streams limit to an extremely high value like 10000** — May cause memory exhaustion and degrade performance; doesn't address inefficient stream usage. (60% 失败率)
- **Disable the stream limit entirely by setting to 0** — gRPC interprets 0 as unlimited, but may cause resource starvation and DoS vulnerability. (70% 失败率)
- **Restart server every time it hits limit** — Temporary fix; the issue recurs as traffic grows. (90% 失败率)
