{
  "id": "go/close-of-closed-channel",
  "signature": "panic: close of closed channel",
  "signature_zh": "panic: 重复关闭 channel",
  "regex": "panic:\\ close\\ of\\ closed\\ channel",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Two goroutines both called close(ch), or a deferred close ran twice because the function was retried. Go panics on the second close.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个 goroutine 都调用了 close(ch)，或函数被重试导致 defer close 执行了两次。Go 在第二次 close 时 panic。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The flag itself is racy without a mutex; two goroutines can both read false and both call close.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the main goroutine is not the sole owner or the function can run concurrently, this does not guarantee single close.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "var closeOnce sync.Once\ncloseOnce.Do(func() { close(ch) })",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "// Only the producer closes\nfunc produce(ch chan<- int, n int) {\n    defer close(ch)\n    for i := 0; i < n; i++ { ch <- i }\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-01-19",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}