{
  "id": "go/unbuffered-channel-blocking",
  "signature": "fatal error: all goroutines are asleep - deadlock! (unbuffered channel)",
  "signature_zh": "致命错误：所有goroutine都在休眠 - 死锁！（无缓冲通道）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(unbuffered\\ channel\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An unbuffered channel requires both sender and receiver to be ready simultaneously. If only one side is ready, it blocks indefinitely.",
  "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"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Making the channel buffered with a small size",
      "why_fails": "A small buffer may not be sufficient; if the buffer fills up, the same deadlock can occur.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using time.Sleep to give the other side time to prepare",
      "why_fails": "Sleeping is non-deterministic and doesn't guarantee both sides are ready; it may still deadlock.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure both sender and receiver are started before the blocking operation",
      "success_rate": 0.9,
      "how": "ch := make(chan int)\n\ngo func() {\n    val := <-ch\n    fmt.Println(val)\n}()\n\nch <- 42 // now this won't block because receiver is ready",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a buffered channel with a reasonable capacity",
      "success_rate": 0.8,
      "how": "ch := make(chan int, 10) // buffer size 10",
      "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-09-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}