go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (WaitGroup)
ID: go/goroutine-leak-on-waitgroup
80%Fix Rate
83%Confidence
0Evidence
2024-08-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
Root Cause
WaitGroup的计数器未归零,主goroutine调用Wait,但子goroutine因阻塞而无法完成。
generic中文
WaitGroup的计数器未归零,主goroutine调用Wait,但子goroutine因阻塞而无法完成。
Workarounds
-
85% success
使用select和done通道通知退出
-
90% success
ctx, cancel := context.WithCancel(context.Background()); go func(){ select { case <-ctx.Done(): return } }()
Dead Ends
Common approaches that don't work:
-
60% fail
超时后goroutine仍在运行,程序可能退出但资源泄漏。
-
70% fail
关闭通道可能引发其他panic,且未解决阻塞原因。