# 致命错误：所有 goroutine 都在休眠 - 死锁！（阻塞在 select {} 中）

- **ID:** `go/select-no-cases-blocks`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

空的 select{} 会永久阻塞当前 goroutine，若它是唯一 goroutine，运行时判定死锁。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
<-ctx.Done()
   ```
2. **** (90% 成功率)
   ```
   done := make(chan struct{})
go func(){ /* work */ close(done) }()
<-done
   ```
3. **** (93% 成功率)
   ```
   for {
    select {
    case <-ctx.Done(): return
    case msg := <-msgs: handle(msg)
    }
}
   ```

## 无效尝试

- **** — Busy-waits and burns CPU; still no way to exit cleanly. (85% 失败率)
- **** — Same deadlock, just a spin loop; runtime still aborts if no other goroutine. (95% 失败率)
- **** — Moves the block elsewhere; leaked goroutine and no shutdown path. (80% 失败率)
