{
  "id": "go/channel-send-on-closed-channel",
  "signature": "panic: send on closed channel",
  "signature_zh": "panic: 向已关闭的 channel 发送数据",
  "regex": "panic:\\ send\\ on\\ closed\\ channel",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine executed ch <- val after another goroutine called close(ch). Sending on a closed channel always panics; the race between sender and closer is the root issue.",
  "root_cause_type": "generic",
  "root_cause_zh": "某个 goroutine 在另一个 goroutine 调用 close(ch) 之后仍执行 ch <- val。向已关闭 channel 发送数据必定 panic，发送方与关闭方之间的竞态是根本原因。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "recover only stops the panic in the current goroutine; the send is logically invalid and the message is silently lost, corrupting downstream logic. Also recover does not work across goroutine boundaries.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Sleep does not establish happens-before ordering; the scheduler may still run the closer after the sender. It only narrows the race window and fails under load.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "done := make(chan struct{})\n// producer owns close\nfunc producer(ch chan int, done <-chan struct{}) {\n    defer close(ch)\n    for i := 0; ; i++ {\n        select {\n        case <-done:\n            return\n        case ch <- i:\n        }\n    }\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "select {\ncase ch <- v:\ncase <-quit:\n    return\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}