# rpc 错误：代码 = Unavailable，描述 = 因连接错误关闭传输：从服务端读取时 EOF，收到先前的 GOAWAY：ENHANCE_YOUR_CALM，调试数据："too_many_pings"

- **ID:** `go/grpc-keepalive-too-aggressive`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

客户端发送 keepalive ping 的频率超过服务端 MinTime 限制，服务端发送 GOAWAY 并附 ENHANCE_YOUR_CALM。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.50+ | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Set client keepalive to at least the server's MinTime (default 5 min):
conn, _ := grpc.NewClient(addr,
  grpc.WithKeepaliveParams(keepalive.ClientParameters{
    Time: 5*time.Minute, Timeout: 20*time.Second, PermitWithoutStream: false,
  }))
   ```
2. **** (85% 成功率)
   ```
   On the server, lower the enforcement threshold:
srv := grpc.NewServer(grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
  MinTime: 10*time.Second, PermitWithoutStream: true,
}))
   ```

## 无效尝试

- **** — Loses detection of dead connections through idle NAT/LB timeouts, causing silent hangs. (60% 失败率)
- **** — MaxConnectionAge is a server option; the client's setting is ignored. (90% 失败率)
