{
  "id": "go/goroutine-racy-channel-close",
  "signature": "WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (channel close)",
  "signature_zh": "警告：数据竞争：协程X写入，协程Y读取（通道关闭）",
  "regex": "WARNING:\\ DATA\\ RACE:\\ Write\\ by\\ goroutine\\ X,\\ Read\\ by\\ goroutine\\ Y\\ \\(channel\\ close\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines trying to close the same channel without synchronization, causing race.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个协程试图关闭同一个通道而没有同步，导致竞争。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using atomic flag to guard close",
      "why_fails": "Close itself is not atomic; still race between check and close.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using recover() to catch double close panic",
      "why_fails": "Recover doesn't prevent race; panic may still occur.",
      "fail_rate": 0.9,
      "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 dedicated closer goroutine",
      "success_rate": 0.85,
      "how": "closeCh := make(chan struct{})\ngo func() {\n    <-closeCh\n    close(ch)\n}()\n// signal close\nclose(closeCh)",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2026-01-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}