go network_error ai_generated true

error: context canceled

ID: go/context-canceled-error

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.17 active
1.21 active

Root Cause

A context was canceled (parent cancel, timeout, or client disconnect) while a downstream operation was in flight. The error surfaces from any context-aware call.

generic

中文

上下文被取消(父级取消、超时或客户端断开),而下游操作正在进行。任何感知上下文的调用都会返回此错误。

Workarounds

  1. 90% success
    if errors.Is(err, context.Canceled) {
        return nil // expected on shutdown
    }
  2. 88% success
    if errors.Is(err, context.DeadlineExceeded) { retry() }
    if errors.Is(err, context.Canceled) { return err }

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Retrying with the same canceled context fails instantly in a tight loop; burns CPU and logs.

  2. 80% fail

    Removes timeout propagation; leaked requests and shutdown hangs.