# panic: runtime error: goroutine stack exceeds 1000000000-byte limit

- **ID:** `go/goroutine-stack-growth-panic`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A goroutine has infinite recursion or excessive stack usage, causing stack overflow.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |

## Workarounds

1. **Convert recursion to iteration** (95% success)
   ```
   // 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% success)
   ```
   type frame struct { n int; result int }
stack := []frame{{n: initial}}
for len(stack) > 0 {
    // process
}
   ```

## Dead Ends

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