{
  "id": "go/goroutine-close-channel-from-sender",
  "signature": "panic: send on closed channel (from sender after close)",
  "signature_zh": "恐慌：向已关闭的通道发送数据（发送者在关闭后发送）",
  "regex": "panic:\\ send\\ on\\ closed\\ channel\\ \\(from\\ sender\\ after\\ close\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Sender goroutine sends to a channel after another goroutine has closed it, often due to 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 recover() to catch panic and log",
      "why_fails": "Recover doesn't fix the race; data may be lost.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Checking channel length before send",
      "why_fails": "len(ch) doesn't indicate closed state; send still panics.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a done channel to signal senders to stop",
      "success_rate": 0.85,
      "how": "done := make(chan struct{})\nch := make(chan int)\ngo func() {\n    for {\n        select {\n        case <-done:\n            return\n        case ch <- 1:\n        }\n    }\n}()\nclose(ch) // but close done first\nclose(done)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use sync.WaitGroup to ensure all sends complete before close",
      "success_rate": 0.9,
      "how": "var wg sync.WaitGroup\nfor i := 0; i < 5; i++ {\n    wg.Add(1)\n    go func() {\n        defer wg.Done()\n        ch <- 1\n    }()\n}\nwg.Wait()\nclose(ch)",
      "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": "2024-11-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}