{
  "id": "go/goroutine-send-on-closed-channel",
  "signature": "panic: send on closed channel",
  "signature_zh": "恐慌：向已关闭的通道发送数据",
  "regex": "panic:\\ send\\ on\\ closed\\ channel",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Sending data to a channel that has already been closed, typically due to multiple goroutines sending without proper synchronization of channel closure.",
  "root_cause_type": "generic",
  "root_cause_zh": "向已经关闭的通道发送数据，通常是由于多个协程发送数据时没有正确同步通道的关闭操作。",
  "versions": [
    {
      "version": "1.21",
      "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": "Checking channel state with a flag before sending",
      "why_fails": "Race condition: the channel could be closed between the check and the send, leading to a panic.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using recover() to catch the panic and continue",
      "why_fails": "Recovering from a panic does not prevent data loss or corruption, and the program state may be inconsistent.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a sync.Mutex to coordinate sends and close",
      "success_rate": 0.95,
      "how": "var mu sync.Mutex\nch := make(chan int)\ncloseCh := func() {\n    mu.Lock()\n    defer mu.Unlock()\n    close(ch)\n}\nsend := func(v int) {\n    mu.Lock()\n    defer mu.Unlock()\n    ch <- v\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a select with default to avoid send on closed channel",
      "success_rate": 0.9,
      "how": "select {\ncase ch <- v:\ndefault:\n    // handle failure or retry\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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}