go resource_error ai_generated true

fatal error: runtime: goroutine stack exceeds 1000000000-byte limit

ID: go/goroutine-leak-unbounded

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.21 active — — —
1.22 active — — —

Root Cause

Unbounded goroutine creation due to missing synchronization or infinite loop, causing stack memory exhaustion.

generic

中文

由于缺少同步或无限循环导致无限制创建协程,造成栈内存耗尽。

Workarounds

  1. 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) }
  2. 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:

  1. Increasing stack size via debug.SetMaxStack 80% fail

    Does not fix leak; only delays exhaustion.

  2. Using runtime.GOMAXPROCS to limit concurrency 90% fail

    Limits CPU parallelism, not goroutine count.