go
resource_error
ai_generated
true
error: runtime: goroutine leak detected: time.Tick never stopped
ID: go/goroutine-leak-time-tick
80%Fix Rate
85%Confidence
0Evidence
2024-11-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
time.Tick returns a channel that is never garbage collected; each call leaks a goroutine for the process lifetime.
generic中文
time.Tick 返回的通道永远不会被垃圾回收;每次调用都会为进程生命周期泄漏一个 goroutine。
Workarounds
-
95% success
t := time.NewTicker(time.Second) defer t.Stop() for range t.C { /* ... */ } -
90% success
timer := time.AfterFunc(time.Second, func() { /* ... */ }) defer timer.Stop()
Dead Ends
Common approaches that don't work:
-
90% fail
Each new ticker adds a goroutine; long-running services leak unboundedly.
-
95% fail
time.Tick's underlying ticker is intentionally retained by the runtime.