{
  "id": "go/panic-runtime-error-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": "Attempting to send a value on a channel that has already been closed, which violates the channel contract.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试向已关闭的通道发送值，违反了通道的使用约定。",
  "versions": [
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a time.Sleep before closing the channel to avoid race conditions.",
      "why_fails": "Race conditions are timing-dependent; adding sleep does not guarantee ordering and may hide the bug rather than fix it.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using recover() in a deferred function to catch the panic.",
      "why_fails": "Recovering from a panic does not fix the root cause; the channel was already misused and data may be lost.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Closing the channel after all sends are done by adding a sync.WaitGroup but not calling WaitGroup.Wait() correctly.",
      "why_fails": "Incorrect WaitGroup usage leads to same race: close happens before all sends complete.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the channel is closed only by the sender after all sends are complete. Use a sync.WaitGroup to coordinate goroutines, and close the channel in a dedicated goroutine after Wait.",
      "success_rate": 0.9,
      "how": "Ensure the channel is closed only by the sender after all sends are complete. Use a sync.WaitGroup to coordinate goroutines, and close the channel in a dedicated goroutine after Wait.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a select statement with a default case to check if the channel is closed before sending, or use a separate closed channel for signaling.",
      "success_rate": 0.85,
      "how": "Use a select statement with a default case to check if the channel is closed before sending, or use a separate closed channel for signaling.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure the channel is closed only by the sender after all sends are complete. Use a sync.WaitGroup to coordinate goroutines, and close the channel in a dedicated goroutine after Wait.",
    "Use a select statement with a default case to check if the channel is closed before sending, or use a separate closed channel for signaling."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#Close",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}