go
resource_error
ai_generated
true
fatal error: out of memory allocating heap arena metadata
ID: go/goroutine-count-explosion
80%Fix Rate
87%Confidence
0Evidence
2024-08-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Unbounded go statement per incoming request or per item spawns millions of goroutines, exhausting memory.
generic中文
对每个传入请求或每个条目无限制地使用 go 语句,生成数百万个 goroutine,耗尽内存。
Workarounds
-
95% success
sem := make(chan struct{}, 100) for _, item := range items { sem <- struct{}{} go func(it Item) { defer func() { <-sem }() process(it) }(item) } -
93% success
jobs := make(chan Job, 1000) for i := 0; i < runtime.NumCPU(); i++ { go func() { for j := range jobs { process(j) } }() }
Dead Ends
Common approaches that don't work:
-
85% fail
Goroutine stacks dominate memory; GC tuning does not reduce goroutine count.
-
70% fail
GOMEMLIMIT forces GC but goroutines keep spawning; OOM still occurs or throughput collapses.