# runtime: goroutine stack exceeds 1000000000-byte limit

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

## Root Cause

A goroutine has infinite recursion or excessive stack allocation, causing stack overflow

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Refactor recursive function to iterative approach** (90% success)
   ```
   func factorial(n int) int {
    result := 1
    for i := 2; i <= n; i++ {
        result *= i
    }
    return result
}
   ```
2. **Use tail recursion with proper termination condition** (85% success)
   ```
   func factorialTail(n, acc int) int {
    if n == 0 {
        return acc
    }
    return factorialTail(n-1, n*acc)
}
   ```

## Dead Ends

- **Increasing stack size via runtime.GOMAXPROCS** — GOMAXPROCS controls parallelism, not stack size; stack limit is fixed by runtime (95% fail)
- **Using more goroutines to distribute work** — More goroutines do not reduce stack usage per goroutine; each still has its own stack (80% fail)
