{
  "id": "go/unbuffered-channel-deadlock-single-goroutine",
  "signature": "fatal error: all goroutines are asleep - deadlock! (unbuffered channel send without receiver)",
  "signature_zh": "致命错误：所有 goroutine 都处于休眠状态 - 死锁！（无缓冲通道发送无接收者）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(unbuffered\\ channel\\ send\\ without\\ receiver\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine tries to send on an unbuffered channel without a corresponding receiver ready, causing it to block forever. If all goroutines are blocked, the program deadlocks.",
  "root_cause_type": "generic",
  "root_cause_zh": "goroutine 尝试在无缓冲通道上发送，但没有相应的接收者准备好，导致其永远阻塞。如果所有 goroutine 都阻塞，程序将死锁。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a buffered channel with size 1 to avoid blocking",
      "why_fails": "A buffered channel can hold one value, but if the receiver never reads, the buffer will fill up and subsequent sends will block, leading to the same deadlock.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a time.Sleep before sending to wait for receiver",
      "why_fails": "Sleep is unreliable; the receiver may not be ready in time, and it introduces unnecessary delays.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the receiver is ready before sending",
      "success_rate": 0.95,
      "how": "ch := make(chan int)\ngo func() {\n    val := <-ch\n    fmt.Println(val)\n}()\nch <- 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a select with a default case to make send non-blocking",
      "success_rate": 0.9,
      "how": "select {\ncase ch <- 42:\ndefault:\n    fmt.Println(\"no receiver, dropping message\")\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-10-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}