go
runtime_error
ai_generated
true
runtime: goroutine stack exceeds 1000000000-byte limit
ID: go/goroutine-stack-overflow
80%Fix Rate
85%Confidence
0Evidence
2024-08-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
A goroutine has infinite recursion or excessive stack allocation, causing stack overflow
generic中文
协程存在无限递归或过多的栈分配,导致栈溢出
Workarounds
-
90% success Refactor recursive function to iterative approach
func factorial(n int) int { result := 1 for i := 2; i <= n; i++ { result *= i } return result } -
85% success Use tail recursion with proper termination condition
func factorialTail(n, acc int) int { if n == 0 { return acc } return factorialTail(n-1, n*acc) }
Dead Ends
Common approaches that don't work:
-
Increasing stack size via runtime.GOMAXPROCS
95% fail
GOMAXPROCS controls parallelism, not stack size; stack limit is fixed by runtime
-
Using more goroutines to distribute work
80% fail
More goroutines do not reduce stack usage per goroutine; each still has its own stack