go network_error ai_generated partial

rpc error: code = Canceled desc = context canceled

ID: go/grpc-context-canceled

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-02-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
go 1.21+ (context.WithoutCancel) active

Root Cause

The caller's context was canceled (e.g., HTTP request aborted, parent context deadline hit, or explicit cancel()) before the RPC completed.

generic

中文

在 RPC 完成前调用方的 context 被取消(例如 HTTP 请求中止、父 context 超时或显式 cancel())。

Workarounds

  1. 90% success
    Detach from the request context for background work:
    ctx = context.WithoutCancel(ctx)
    // or use context.Background() with an explicit timeout
  2. 85% success
    Distinguish cancellation from real failures:
    if status.Code(err) == codes.Canceled {
        return // caller went away, do not log as error
    }

Dead Ends

Common approaches that don't work:

  1. 99% fail

    An already-canceled context immediately fails every subsequent call.

  2. 80% fail

    The cancellation originates on the client side; server timeouts are irrelevant.