{
  "id": "go/grpc-context-canceled-client",
  "signature": "rpc error: code = Canceled desc = context canceled",
  "signature_zh": "rpc 错误：code = Canceled desc = 上下文已取消",
  "regex": "rpc\\ error:\\ code\\ =\\ Canceled\\ desc\\ =\\ context\\ canceled",
  "domain": "go",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The client canceled the context (e.g., HTTP request aborted, timeout on parent ctx, or explicit cancel()) before the RPC completed.",
  "root_cause_type": "generic",
  "root_cause_zh": "客户端在 RPC 完成前取消了上下文（例如 HTTP 请求中止、父 ctx 超时或显式调用 cancel()）。",
  "versions": [
    {
      "version": "google.golang.org/grpc v1.50+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If the caller canceled, the retry will also be canceled immediately — wasted work.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses parent deadline/cancellation propagation; goroutines leak on client disconnect.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "resp, err := client.Get(ctx, req)\nif err != nil {\n    if errors.Is(ctx.Err(), context.Canceled) {\n        log.Printf(\"caller canceled: %v\", ctx.Err())\n        return nil, err\n    }\n    if status.Code(err) == codes.Canceled {\n        return nil, status.Error(codes.Canceled, \"server canceled RPC\")\n    }\n    return nil, err\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "for {\n    select {\n    case <-ctx.Done():\n        return nil, status.FromContextError(ctx.Err()).Err()\n    default:\n        // do work\n    }\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-06",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}