{
  "id": "go/channel-range-without-close",
  "signature": "fatal error: all goroutines are asleep - deadlock! (range over channel)",
  "signature_zh": "致命错误：所有 goroutine 都处于休眠状态 - 死锁！（在通道上范围遍历）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(range\\ over\\ channel\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Ranging over a channel that is never closed and has no more values blocks forever.",
  "root_cause_type": "generic",
  "root_cause_zh": "在从未关闭且没有更多值的通道上进行范围遍历会永久阻塞。",
  "versions": [
    {
      "version": "1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Break only exits if condition met; if no values, still blocks.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Range doesn't support timeout; need select.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the channel is never sent to, still blocks.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "ch := make(chan int)\ngo func() { defer close(ch); for i:=0;i<5;i++ { ch<-i } }()\nfor v := range ch {\n    fmt.Println(v)\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "for {\n    select {\n    case v, ok := <-ch:\n        if !ok { return }\n        fmt.Println(v)\n    case <-time.After(time.Second):\n        return\n    }\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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}