# 致命错误：运行时：协程栈超过1000000000字节限制

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

## 根因

协程因在通道或锁上永久阻塞而泄漏，导致栈内存无限制增长。

## 版本兼容性

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

## 解决方案

1. **Use context with timeout to unblock goroutines** (95% 成功率)
   ```
   ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
select {
case <-ch:
case <-ctx.Done():
    // timeout, handle cleanup
}
   ```
2. **Ensure every goroutine has a clear exit path** (98% 成功率)
   ```
   done := make(chan struct{})
go func() {
    defer close(done)
    // work
}()
<-done
   ```

## 无效尝试

- **Increasing stack limit** — Does not fix the leak; only delays the crash. (95% 失败率)
- **Using time.Sleep to periodically check** — Sleep does not unblock goroutines; they remain blocked. (90% 失败率)
