{
  "id": "go/channel-receive-from-nil-channel",
  "signature": "fatal error: all goroutines are asleep - deadlock! (nil channel receive)",
  "signature_zh": "fatal error: 所有 goroutine 都处于休眠状态 - 死锁！（nil channel 接收）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(nil\\ channel\\ receive\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine attempted to receive from a nil channel, which blocks forever. If all goroutines are blocked on nil channels, the runtime detects a deadlock.",
  "root_cause_type": "generic",
  "root_cause_zh": "某个 goroutine 尝试从 nil channel 接收数据，这会永久阻塞。如果所有 goroutine 都阻塞在 nil channel 上，运行时会检测到死锁。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "A nil channel is not the same as an uninitialized variable; you must explicitly create it with make().",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "A select with a nil channel case will block if no other case is ready; default only helps if you want non-blocking behavior.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "ch := make(chan int)\n// or ch := make(chan int, 1)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "select {\ncase v := <-ch:\n    // use v\ncase <-time.After(1 * time.Second):\n    return errors.New(\"timeout: channel may be nil\")\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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}