{
  "id": "go/context-cancellation-ignore",
  "signature": "panic: runtime error: send on closed channel (context cancellation)",
  "signature_zh": "恐慌：运行时错误：向已关闭的通道发送数据（上下文取消）",
  "regex": "panic:\\ runtime\\ error:\\ send\\ on\\ closed\\ channel\\ \\(context\\ cancellation\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When a context is cancelled, its channel is closed; sending on it causes a panic.",
  "root_cause_type": "generic",
  "root_cause_zh": "当上下文被取消时，其通道被关闭；向其发送数据会导致恐慌。",
  "versions": [
    {
      "version": "1.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Checking context.Err() before send but not handling race condition",
      "why_fails": "Context can be cancelled between check and send.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a separate channel that is not closed on cancellation",
      "why_fails": "Ignores the cancellation signal, leading to resource leaks.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use select with context.Done() to avoid sending on closed channel",
      "success_rate": 0.95,
      "how": "select {\ncase ch <- data:\ncase <-ctx.Done():\n    return ctx.Err()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Create a new channel for each operation and close it safely",
      "success_rate": 0.9,
      "how": "ch := make(chan int, 1)\nselect {\ncase ch <- data:\ncase <-ctx.Done():\n    close(ch)\n    return ctx.Err()\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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}