go
resource_error
ai_generated
true
fatal error: runtime: out of memory (timer leak)
ID: go/goroutine-timer-leak
80%Fix Rate
85%Confidence
0Evidence
2025-12-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.20 | active | — | — | — |
Root Cause
Creating time.Timer or time.Ticker without stopping them, causing goroutine leak and memory exhaustion.
generic中文
创建time.Timer或time.Ticker而不停止它们,导致协程泄漏和内存耗尽。
Workarounds
-
95% success Always stop timers and tickers when done
ticker := time.NewTicker(time.Second) defer ticker.Stop() for range ticker.C { // do work } -
85% success Use time.After with select and timeout
select { case <-ch: case <-time.After(5 * time.Second): // timeout }
Dead Ends
Common approaches that don't work:
-
Using time.After repeatedly without reset
90% fail
time.After creates new timer each call; old timers are not garbage collected until fired.
-
Ignoring ticker stop in defer
80% fail
Ticker continues to tick; goroutine leaks.