{
  "id": "go/goroutine-channel-receive-from-nil",
  "signature": "fatal error: all goroutines are asleep - deadlock! (receive from nil channel)",
  "signature_zh": "致命错误：所有协程都处于休眠状态 - 死锁！（从 nil 通道接收）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(receive\\ from\\ nil\\ channel\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine attempts to receive from a nil channel, which blocks indefinitely, causing a deadlock if no other goroutine can unblock it.",
  "root_cause_type": "generic",
  "root_cause_zh": "协程尝试从 nil 通道接收数据，这会导致无限阻塞，如果没有其他协程可以解除阻塞，则会导致死锁。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.20",
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Initialize channel in init()",
      "why_fails": "If the channel is used before init() runs, it remains nil.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the nil channel and add a timeout",
      "why_fails": "Timeout doesn't fix the root cause; the channel is still nil and will block again.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure channel is initialized before use",
      "success_rate": 1.0,
      "how": "ch := make(chan int)\n// use ch",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a default case in select to avoid blocking",
      "success_rate": 0.9,
      "how": "select {\ncase val := <-ch:\n    // process\ncase <-time.After(1 * time.Second):\n    // timeout\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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}