go
resource_error
ai_generated
true
fatal error: runtime: goroutine stack exceeds 1000000000-byte limit
ID: go/goroutine-leak-unbounded
80%Fix Rate
82%Confidence
0Evidence
2024-06-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Unbounded goroutine creation due to missing synchronization or infinite loop, causing stack memory exhaustion.
generic中文
由于缺少同步或无限循环导致无限制创建协程,造成栈内存耗尽。
Workarounds
-
95% success Use worker pool with buffered channel to limit goroutines
sem := make(chan struct{}, 100); for _, task := range tasks { sem <- struct{}{}; go func(t Task) { defer func() { <-sem }(); process(t) }(task) } -
90% success Add context cancellation to stop goroutines
ctx, cancel := context.WithCancel(context.Background()); go func() { select { case <-ctx.Done(): return; default: work() } }(); cancel()
Dead Ends
Common approaches that don't work:
-
Increasing stack size via debug.SetMaxStack
80% fail
Does not fix leak; only delays exhaustion.
-
Using runtime.GOMAXPROCS to limit concurrency
90% fail
Limits CPU parallelism, not goroutine count.