{
  "id": "go/grpc-canceled-context-cancelled",
  "signature": "rpc error: code = Canceled desc = context canceled",
  "signature_zh": "rpc错误：代码=已取消 描述=上下文已取消",
  "regex": "rpc\\ error:\\ code\\ =\\ Canceled\\ desc\\ =\\ context\\ canceled",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The client cancelled the context before the RPC completed, often due to user action or timeout.",
  "root_cause_type": "generic",
  "root_cause_zh": "客户端在RPC完成之前取消了上下文，通常是由于用户操作或超时。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignore the cancellation and retry with the same context.",
      "why_fails": "The cancelled context cannot be reused; a new context is needed.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove context cancellation logic entirely.",
      "why_fails": "This can lead to resource leaks and unresponsive applications.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Create a new context for each RPC call to avoid using cancelled contexts.",
      "success_rate": 0.9,
      "how": "ctx := context.Background()\nresp, err := client.SomeRPC(ctx, req)\nif err != nil {\n    if status.Code(err) == codes.Canceled {\n        // Create new context and retry if appropriate\n        ctx2 := context.Background()\n        resp, err = client.SomeRPC(ctx2, req)\n    }\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Handle cancellation gracefully by checking context errors.",
      "success_rate": 0.85,
      "how": "select {\ncase <-ctx.Done():\n    return nil, ctx.Err()\ndefault:\n}\nresp, err := client.SomeRPC(ctx, req)",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-03-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}