{
  "id": "go/receive-on-closed-channel-loop",
  "signature": "error: channel closed but reads return zero values indefinitely",
  "signature_zh": "错误：通道已关闭但读取无限返回零值",
  "regex": "error:\\ channel\\ closed\\ but\\ reads\\ return\\ zero\\ values\\ indefinitely",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Reading from a closed channel never blocks; it returns the zero value and ok=false immediately. A for-range loop only exits when the channel is closed, but a manual <-ch in a loop spins forever.",
  "root_cause_type": "generic",
  "root_cause_zh": "从已关闭的通道读取不会阻塞，会立即返回零值和 ok=false。for-range 循环仅在通道关闭时退出，但手动在循环里使用 <-ch 会无限自旋。",
  "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"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Reduces CPU burn but the loop still never terminates; the program hangs and leaks goroutines.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "len returns buffered items, not closure state. A closed empty channel has len 0, same as an open empty one.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "for {\n    v, ok := <-ch\n    if !ok { break }\n    process(v)\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.98,
      "how": "for v := range ch {\n    process(v)\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}