{
  "id": "go/receive-on-nil-channel-blocks",
  "signature": "fatal error: all goroutines are asleep - deadlock! (receive on nil channel)",
  "signature_zh": "致命错误：所有 goroutine 都休眠——死锁（在 nil channel 上接收）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(receive\\ on\\ nil\\ channel\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A receive from a nil channel blocks forever. If the channel variable was never assigned and is used in a select or receive, the goroutine hangs permanently.",
  "root_cause_type": "generic",
  "root_cause_zh": "从 nil channel 接收会永久阻塞。若 channel 变量从未被赋值却用于 select 或接收，goroutine 将永久挂起。",
  "versions": [
    {
      "version": "1.18",
      "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": "It prevents the hang but the underlying nil channel is still never populated, so the program silently times out instead of working.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The default case fires immediately forever, spinning in a busy loop consuming CPU.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "ch := make(chan int)\ngo func() { ch <- 1 }()\nv := <-ch\nfmt.Println(v)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "select {\ncase v := <-ch:\n    fmt.Println(v)\ncase <-ctx.Done():\n    return ctx.Err()\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.86,
  "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": []
}