{
  "id": "go/grpc-stream-canceled-by-client",
  "signature": "rpc error: code = Canceled desc = context canceled",
  "signature_zh": "rpc 错误：代码 = Canceled，描述 = 上下文已取消",
  "regex": "rpc\\ error:\\ code\\ =\\ Canceled\\ desc\\ =\\ context\\ canceled",
  "domain": "go",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The caller's context was canceled (client timeout, user request abort, or upstream context propagation) before the RPC returned.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 RPC 返回前，调用方的上下文被取消（客户端超时、用户请求中止或上游上下文传播）。",
  "versions": [
    {
      "version": "1.40+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "A canceled context stays canceled; the retry fails immediately.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Masks upstream cancellation and can leak goroutines / leave server resources allocated.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Create a fresh context for retries with a bounded deadline:\nretryCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)\ndefer cancel()\nresp, err := client.Do(retryCtx, req)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "On the server, honor ctx.Done() and clean up resources:\n<-ctx.Done()\n// release DB conn, cancel downstream calls",
      "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": "2025-01-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}