# UNAVAILABLE: grpc: 流空闲超时

- **ID:** `grpc/stream-idle-timeout`
- **领域:** grpc
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

流式RPC长时间不活动（没有发送或接收数据），由于空闲超时配置，服务器或客户端关闭了流。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC Go 1.50+ | active | — | — |
| gRPC Python 1.50+ | active | — | — |
| Nginx gRPC proxy 1.25+ | active | — | — |

## 解决方案

1. ```
   Send periodic keepalive pings from client. In Go: grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 30 * time.Second, Timeout: 10 * time.Second}). Set server: keepalive.ServerParameters{MaxConnectionIdle: 5 * time.Minute}
   ```
2. ```
   Use bidirectional streaming with periodic heartbeat messages. In Python: every 10 seconds send a small protobuf message (e.g., Empty) from client and have server echo it back.
   ```

## 无效尝试

- **Setting keepalive time to 0 (disable)** — May cause connections to be dropped by network middleboxes that expect periodic traffic. (40% 失败率)
- **Increasing timeout on server only** — Client may still have its own idle timeout that triggers first. (35% 失败率)
