go
resource_error
ai_generated
true
fatal error: runtime: out of memory
ID: go/goroutine-not-scheduled
80%Fix Rate
87%Confidence
0Evidence
2024-06-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
Creating an excessive number of goroutines without limit, exhausting system memory.
generic中文
无限创建 goroutine,导致系统内存耗尽。
Workarounds
-
95% success
Use a worker pool pattern: const maxWorkers = 10 jobs := make(chan int) var wg sync.WaitGroup for i := 0; i < maxWorkers; i++ { wg.Add(1) go func() { defer wg.Done() for j := range jobs { process(j) } }() } // send jobs and close -
90% success
Use semaphore channel to limit goroutine count: sem := make(chan struct{}, 10) for _, task := range tasks { sem <- struct{}{} go func(t task) { defer func() { <-sem }() process(t) }(task) }
Dead Ends
Common approaches that don't work:
-
90% fail
Temporary fix; doesn't solve the underlying goroutine leak.
-
70% fail
WaitGroup doesn't limit concurrency; it only waits for all to finish.