{
  "id": "go/goroutine-unbuffered-channel-blocking",
  "signature": "fatal error: all goroutines are asleep - deadlock! (unbuffered channel send)",
  "signature_zh": "致命错误：所有协程都在休眠 - 死锁！（无缓冲通道发送）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(unbuffered\\ channel\\ send\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An unbuffered channel send blocks until a receiver is ready; if no receiver exists, the goroutine deadlocks.",
  "root_cause_type": "generic",
  "root_cause_zh": "无缓冲通道发送会阻塞直到有接收者就绪；如果没有接收者，协程会死锁。",
  "versions": [
    {
      "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": "Using a buffered channel but with size 0, which is unbuffered.",
      "why_fails": "make(chan int, 0) creates an unbuffered channel, still blocking.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a receiver in the same goroutine after the send.",
      "why_fails": "The send blocks before the receiver is reached, causing deadlock.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a buffered channel to allow sends without immediate receiver.",
      "success_rate": 0.95,
      "how": "ch := make(chan int, 1)\nch <- 42 // non-blocking\nval := <-ch\nfmt.Println(val)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure a receiver goroutine is started before sending.",
      "success_rate": 1.0,
      "how": "ch := make(chan int)\ngo func() {\n    val := <-ch\n    fmt.Println(val)\n}()\nch <- 42 // now receiver is ready",
      "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-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}