# 内部错误：gRPC 流 45 因空闲超时关闭

- **ID:** `grpc/stream-idle-timeout-reset`
- **领域:** grpc
- **类别:** runtime_error
- **错误码:** `GRPC_STREAM_IDLE_TIMEOUT`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

gRPC 服务器因每流空闲超时配置关闭了空闲流，通常由客户端在超时窗口内未发送数据引起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.50.x | active | — | — |
| gRPC v1.62.x | active | — | — |
| gRPC v1.64.x | active | — | — |

## 解决方案

1. ```
   增加服务器端流空闲超时时间：在 Python 中设置 `grpc.max_connection_idle_ms` 为 60000 毫秒，或 C++ 中设置 `GRPC_ARG_MAX_CONNECTION_IDLE_MS`，避免空闲流过早关闭。
   ```
2. ```
   客户端定期发送数据或心跳消息（每 10-15 秒），保持流活跃。
   ```
3. ```
   降低服务器 `max_connection_age_ms` 和 `max_connection_age_grace_ms`，强制连接重新平衡，重置空闲计数器。
   ```

## 无效尝试

- **** — Keepalive pings prevent connection-level idle, but per-stream idle timeouts are separate and not affected by keepalive pings. (70% 失败率)
- **** — This controls minimum allowed ping interval, not stream idle timeout; it doesn't prevent stream closure due to inactivity. (60% 失败率)
- **** — Removing keepalive can cause connection drops, but stream idle timeout is a separate server-side policy that still applies. (50% 失败率)
