# 不可用：gRPC HTTP2 ping 超时（10 秒后），关闭连接

- **ID:** `grpc/http2-ping-timeout`
- **领域:** grpc
- **类别:** network_error
- **错误码:** `GRPC_HTTP2_PING_TIMEOUT`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

gRPC 客户端发送 HTTP/2 ping 但未在超时时间内收到服务器响应，表明网络问题或服务器过载。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC v1.48.x | active | — | — |
| gRPC v1.56.x | active | — | — |
| gRPC v1.63.x | active | — | — |

## 解决方案

1. ```
   增加客户端和服务器的 keepalive 超时时间：设置 `GRPC_ARG_KEEPALIVE_TIMEOUT_MS` 为 20000 毫秒（20 秒），确保服务器端也同步增加。
   ```
2. ```
   检查网络路径是否存在丢包或高延迟（使用 mtr 或 ping）。如果在负载均衡器后，确保支持 HTTP/2 ping 响应并设置适当的超时。
   ```
3. ```
   减少 keepalive ping 间隔（`GRPC_ARG_KEEPALIVE_TIME_MS`）到 10000 毫秒（10 秒），更快检测故障并重新连接。
   ```

## 无效尝试

- **** — This only extends the wait for ping responses; if the network is unreliable, pings still fail, and the connection closes after a longer delay. (65% 失败率)
- **** — Without pings, idle connections may be dropped by middleboxes (e.g., NATs, load balancers), leading to different errors like connection reset. (55% 失败率)
- **** — This pings only when streams are active; if the issue is network latency, pings still time out. (60% 失败率)
