# 致命错误：所有goroutine都处于休眠状态 - 死锁！（goroutine泄漏）

- **ID:** `go/goroutine-leak-channel-buffer`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

由于通道发送没有接收者且通道无缓冲，goroutine永远阻塞。

## 版本兼容性

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

## 解决方案

1. **Ensure every send has a corresponding receive** (95% 成功率)
   ```
   // Before: ch <- 1 (no reader)
// After: 
result := make(chan int)
go func() { result <- doWork() }()
val := <-result
   ```
2. **Use a context with cancellation to clean up goroutines** (90% 成功率)
   ```
   ctx, cancel := context.WithCancel(context.Background())
go func() {
    select {
    case ch <- val:
    case <-ctx.Done():
        return
    }
}()
cancel() // cleanup
   ```

## 无效尝试

- **Increasing buffer size arbitrarily** — Only delays the leak; doesn't match send/receive pattern. (70% 失败率)
- **Using time.After to timeout** — Goroutine still exists but leaks after timeout; not a clean solution. (60% 失败率)
