# UNAVAILABLE: grpc: 收到服务器GOAWAY，原因是ping过多

- **ID:** `grpc/too-many-pings`
- **领域:** grpc
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

客户端发送ping的频率过高，超过了服务器的max_pings_without_data或min_time_between_pings设置，导致服务器发送GOAWAY并关闭连接。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gRPC C++ 1.50+ | active | — | — |
| gRPC Go 1.50+ | active | — | — |
| Envoy 1.25+ | active | — | — |
| Istio 1.18+ | active | — | — |

## 解决方案

1. ```
   Set client-side keepalive parameters: keepalive_time=30s, keepalive_timeout=10s, and min_time_between_pings=5s. In Go: grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 30 * time.Second, Timeout: 10 * time.Second, MinTimeBetweenPings: 5 * time.Second})
   ```
2. ```
   Configure server-side max_pings_without_data to a higher value (e.g., 5) or increase min_time_between_pings (e.g., 10s). In C++ server builder: builder.AddChannelArgument(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 10000);
   ```

## 无效尝试

- **Increasing keepalive time without adjusting ping interval** — The issue is not the keepalive time but the ping frequency; increasing keepalive time alone may not reduce ping rate if min_time_between_pings is violated. (40% 失败率)
- **Disabling keepalive entirely** — Disabling keepalive can cause long-lived connections to be dropped by middleboxes (e.g., NAT, firewalls) that expect periodic traffic. (30% 失败率)
