{
  "id": "go/goroutine-close-channel-twice",
  "signature": "panic: close of closed channel",
  "signature_zh": "恐慌：关闭已关闭的通道",
  "regex": "panic:\\ close\\ of\\ closed\\ channel",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling close() on a channel that has already been closed, often due to multiple goroutines closing without coordination.",
  "root_cause_type": "generic",
  "root_cause_zh": "对已关闭的通道调用close()，通常由于多个协程未经协调地关闭。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using recover() to catch panic and ignore",
      "why_fails": "Recover hides the error but doesn't prevent data race or inconsistent state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Checking ch != nil before close",
      "why_fails": "A closed channel is not nil; nil check doesn't prevent double close.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use sync.Once to ensure close is called only once",
      "success_rate": 0.95,
      "how": "var once sync.Once\nonce.Do(func() { close(ch) })",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a closed flag with mutex",
      "success_rate": 0.9,
      "how": "var mu sync.Mutex\nvar closed bool\nmu.Lock()\nif !closed {\n    close(ch)\n    closed = true\n}\nmu.Unlock()",
      "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-04-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}