{
  "id": "go/select-no-cases-blocks",
  "signature": "fatal error: all goroutines are asleep - deadlock! (blocked in select {})",
  "signature_zh": "致命错误：所有 goroutine 都在休眠 - 死锁！（阻塞在 select {} 中）",
  "regex": "fatal\\ error:\\ all\\ goroutines\\ are\\ asleep\\ \\-\\ deadlock!\\ \\(blocked\\ in\\ select\\ \\{\\}\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An empty select{} blocks the current goroutine forever, and if it is the only goroutine, the runtime deadlocks.",
  "root_cause_type": "generic",
  "root_cause_zh": "空的 select{} 会永久阻塞当前 goroutine，若它是唯一 goroutine，运行时判定死锁。",
  "versions": [
    {
      "version": "1.18",
      "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": "",
      "why_fails": "Busy-waits and burns CPU; still no way to exit cleanly.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same deadlock, just a spin loop; runtime still aborts if no other goroutine.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Moves the block elsewhere; leaked goroutine and no shutdown path.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)\ndefer stop()\n<-ctx.Done()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "done := make(chan struct{})\ngo func(){ /* work */ close(done) }()\n<-done",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "for {\n    select {\n    case <-ctx.Done(): return\n    case msg := <-msgs: handle(msg)\n    }\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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-21",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}