go network_error ai_generated true

rpc error: code = Canceled desc = grpc: the client connection is closing

ID: go/grpc-canceled-context

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-12-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active

Root Cause

The client's gRPC connection was closed (e.g., via conn.Close()) while a request was in flight, causing the RPC to be canceled.

generic

中文

客户端 gRPC 连接在请求进行中被关闭(例如通过 conn.Close()),导致 RPC 被取消。

Workarounds

  1. 85% success
    if conn == nil { conn, _ = grpc.Dial(address, grpc.WithInsecure()) }; resp, err := client.Call(ctx, ...)
  2. 80% success
    Implement a pool that returns a new connection if the old one is closed.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The connection is closed; subsequent requests will also fail.

  2. 90% fail

    The connection is already closed; you need a new connection.