go network_error ai_generated true

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

rpc error: code = Unavailable desc = closing transport due to: connection error: desc = "error reading from server: EOF", received prior goaway: code: ENHANCE_YOUR_CALM, debug data: "too_many_pings"

ID: go/grpc-keepalive-too-aggressive

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-10-15首次发现

版本兼容性

版本状态引入弃用备注
1.50+ active

根因分析

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

English

The client sends keepalive pings more frequently than the server's MinTime permits, causing the server to send GOAWAY with ENHANCE_YOUR_CALM.

generic

解决方案

  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,
    }))

无效尝试

常见但无效的做法:

  1. 60% 失败

    Loses detection of dead connections through idle NAT/LB timeouts, causing silent hangs.

  2. 90% 失败

    MaxConnectionAge is a server option; the client's setting is ignored.