go
resource_error
ai_generated
true
runtime: goroutine count grows unbounded (observed via runtime.NumGoroutine())
ID: go/goroutine-leak-pprof
80%Fix Rate
87%Confidence
0Evidence
2024-06-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Goroutines block forever on channel send/receive or wait on a context that is never cancelled, so they never exit.
generic中文
goroutine 永远阻塞在 channel 发送/接收上,或等待一个永不取消的 context,因此永不退出。
Workarounds
-
90% success
go func(ctx context.Context) { select { case <-ctx.Done(): return case work <- job: } }(ctx) -
88% success
import _ "net/http/pprof" // go tool pprof http://localhost:6060/debug/pprof/goroutine
Dead Ends
Common approaches that don't work:
-
95% fail
GC does not kill blocked goroutines.
-
85% fail
Delays OOM but goroutines still accumulate.