go runtime_error ai_generated true

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

ID: go/goroutine-goroutine-leak

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-04-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.21 active
1.22 active

Root Cause

Goroutines are leaked because they are blocked forever on channels or locks, causing stack memory to grow unboundedly.

generic

中文

协程因在通道或锁上永久阻塞而泄漏,导致栈内存无限制增长。

Workarounds

  1. 95% success Use context with timeout to unblock goroutines
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()
    select {
    case <-ch:
    case <-ctx.Done():
        // timeout, handle cleanup
    }
  2. 98% success Ensure every goroutine has a clear exit path
    done := make(chan struct{})
    go func() {
        defer close(done)
        // work
    }()
    <-done

Dead Ends

Common approaches that don't work:

  1. Increasing stack limit 95% fail

    Does not fix the leak; only delays the crash.

  2. Using time.Sleep to periodically check 90% fail

    Sleep does not unblock goroutines; they remain blocked.