# goroutine 阻塞在 select 上，没有就绪的 case（死锁或长时间停滞）

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

## 根因

没有 default 的 select 语句会阻塞直到某个 case 可以执行。如果所有 channel 永远不会就绪，goroutine 将无限期停滞。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0+ | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   select {
case v := <-ch:
	use(v)
case <-time.After(5 * time.Second):
	return errors.New("timeout waiting for value")
}
   ```
2. **** (90% 成功率)
   ```
   select {
case v := <-ch:
	use(v)
case <-ctx.Done():
	return ctx.Err()
}
   ```

## 无效尝试

- **** — A default with a loop spins the CPU at 100% and does not make any channel ready. (90% 失败率)
- **** — If the channels are never written to, more cases do not help; the goroutine still blocks. (80% 失败率)
