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

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

## 根因

由于缺少同步或无限循环导致无限制创建协程，造成栈内存耗尽。

## 版本兼容性

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

## 解决方案

1. **Use worker pool with buffered channel to limit goroutines** (95% 成功率)
   ```
   sem := make(chan struct{}, 100); for _, task := range tasks { sem <- struct{}{}; go func(t Task) { defer func() { <-sem }(); process(t) }(task) }
   ```
2. **Add context cancellation to stop goroutines** (90% 成功率)
   ```
   ctx, cancel := context.WithCancel(context.Background()); go func() { select { case <-ctx.Done(): return; default: work() } }(); cancel()
   ```

## 无效尝试

- **Increasing stack size via debug.SetMaxStack** — Does not fix leak; only delays exhaustion. (80% 失败率)
- **Using runtime.GOMAXPROCS to limit concurrency** — Limits CPU parallelism, not goroutine count. (90% 失败率)
