go network_error ai_generated partial

rpc error: code = Unavailable desc = error reading from server: EOF

ID: go/grpc-connection-closing-transport

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-07-21First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
grpc-go 1.58+ active — — —

Root Cause

The server closed the HTTP/2 connection mid-stream. Typically the server process exited, was restarted, or a proxy/load balancer dropped the connection.

generic

中文

服务器在流传输中途关闭了 HTTP/2 连接。通常是服务器进程退出、重启,或代理/负载均衡器断开了连接。

Workarounds

  1. 85% success
    Enable client keepalive to detect dead connections quickly:
    conn, err := grpc.NewClient(addr,
        grpc.WithKeepaliveParams(keepalive.ClientParameters{
            Time: 10 * time.Second, Timeout: 3 * time.Second, PermitWithoutStream: true,
        }),
    )
  2. 82% success
    Add a retry policy for UNAVAILABLE and inspect server logs for crashes:
    // configure retryableStatusCodes: ["UNAVAILABLE"] in the service config, then check server OOM/panic logs.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    The error originates at the transport layer from the server side closing the connection; the client handler is not at fault.

  2. 80% fail

    Disabling keepalive does not prevent the server from closing; it actually makes stale connections harder to detect.