# 恐慌：运行时错误：goroutine栈超过1000000000字节限制

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

## 根因

goroutine存在无限递归或栈使用过多，导致栈溢出。

## 版本兼容性

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

## 解决方案

1. **Convert recursion to iteration** (95% 成功率)
   ```
   // Before: func factorial(n int) int { if n <= 1 { return 1 }; return n * factorial(n-1) }
// After:
func factorial(n int) int {
    result := 1
    for i := 2; i <= n; i++ {
        result *= i
    }
    return result
}
   ```
2. **Use a bounded depth-first search with explicit stack** (90% 成功率)
   ```
   type frame struct { n int; result int }
stack := []frame{{n: initial}}
for len(stack) > 0 {
    // process
}
   ```

## 无效尝试

- **Increasing stack size via debug.SetMaxStack** — Only postpones the crash; doesn't fix the underlying bug. (90% 失败率)
- **Using more goroutines to distribute work** — Each goroutine has its own stack; doesn't solve recursion issue. (80% 失败率)
