{
  "id": "go/context-canceled-in-goroutine",
  "signature": "context canceled",
  "signature_zh": "context 已取消",
  "regex": "context\\ canceled",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A context was canceled (either by timeout, deadline, or explicit cancel) while a goroutine was still using it. The goroutine receives context.Canceled error from a function that respects the context.",
  "root_cause_type": "generic",
  "root_cause_zh": "上下文被取消（由于超时、截止时间或显式取消），而某个 goroutine 仍在使用它。该 goroutine 从遵循上下文的函数中收到 context.Canceled 错误。",
  "versions": [
    {
      "version": "1.7+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Ignoring cancellation can lead to resource leaks, wasted work, and violating the contract of context-aware functions.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This loses the cancellation signal and any deadlines, potentially causing the goroutine to run indefinitely.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "select {\ncase <-ctx.Done():\n    return ctx.Err()\ndefault:\n    // continue\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()",
      "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-10-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}