go network_error ai_generated true

rpc error: code = Unavailable desc = transport is closing

ID: go/grpc-code-unavailable-transport-closing

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-08-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/grpc 1.55+ active — — —

Root Cause

The underlying HTTP/2 transport was torn down mid-RPC (server restart, idle timeout, or GOAWAY frame from load balancer).

generic

中文

底层 HTTP/2 传输在 RPC 中途被拆除(服务端重启、空闲超时,或负载均衡器发送 GOAWAY 帧)。

Workarounds

  1. 92% success
    Enable client-side retry policy via service config:
    conn, _ := grpc.NewClient(addr,
      grpc.WithDefaultServiceConfig(`{"methodConfig":[{"name":[{}],"retryPolicy":{"maxAttempts":5,"initialBackoff":"0.1s","maxBackoff":"1s","backoffMultiplier":2,"retryableStatusCodes":["UNAVAILABLE"]}}]}`))
  2. 88% success
    Tune keepalive to detect dead transports faster:
    grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 30*time.Second, Timeout: 10*time.Second, PermitWithoutStream: true})

Dead Ends

Common approaches that don't work:

  1. 85% fail

    WithBlock only affects dial; the in-flight RPC still fails with Unavailable.

  2. 70% fail

    Keepalive is what detects dead transports; disabling it hides the symptom but leaves zombie connections.