# fatal error：所有 goroutine 都休眠——死锁！（select 无就绪分支）

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

## 根因

没有 default 的 select 语句会阻塞直到某个 case 就绪。如果没有任何 channel 就绪，程序死锁。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   select {
case v := <-ch:
    use(v)
case <-time.After(5 * time.Second):
    return errTimeout
}
   ```
2. **** (96% 成功率)
   ```
   select {
case v := <-ch:
    use(v)
case <-ctx.Done():
    return ctx.Err()
}
   ```

## 无效尝试

- **** — The select now spins in a busy loop consuming CPU without ever making progress. (70% 失败率)
- **** — Creates a livelock if no case is ever ready; the program hangs forever. (80% 失败率)
