# 错误：通道已关闭但读取无限返回零值

- **ID:** `go/receive-on-closed-channel-loop`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

从已关闭的通道读取不会阻塞，会立即返回零值和 ok=false。for-range 循环仅在通道关闭时退出，但手动在循环里使用 <-ch 会无限自旋。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   for {
    v, ok := <-ch
    if !ok { break }
    process(v)
}
   ```
2. **** (98% 成功率)
   ```
   for v := range ch {
    process(v)
}
   ```

## 无效尝试

- **** — Reduces CPU burn but the loop still never terminates; the program hangs and leaks goroutines. (90% 失败率)
- **** — len returns buffered items, not closure state. A closed empty channel has len 0, same as an open empty one. (85% 失败率)
