Ticker leaks if timeout is used
Closed this issue · 0 comments
fako1024 commented
When using a timeout for a request a time.Ticker
is created for every retry attempt. Aside from the fact that a ticker isn't the optimal tool for this (a time.Timer
would be better suited), Stop()
is never called and hence the ticker will receive events for all eternity (which can accumulate quite a lot of resources if timeouts are used repeatedly):
flat flat% sum% cum cum%
1500ms 31.06% 31.06% 1500ms 31.06% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1112
630ms 13.04% 44.10% 630ms 13.04% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1118
590ms 12.22% 56.31% 590ms 12.22% runtime/internal/syscall.Syscall6 /usr/local/go/src/runtime/internal/syscall/asm_linux_amd64.s:36
380ms 7.87% 64.18% 380ms 7.87% runtime.chansend /usr/local/go/src/runtime/chan.go:193
190ms 3.93% 68.12% 190ms 3.93% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1111
180ms 3.73% 71.84% 180ms 3.73% time.Now /usr/local/go/src/time/time.go:1111
170ms 3.52% 75.36% 170ms 3.52% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1130
90ms 1.86% 77.23% 90ms 1.86% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1122
70ms 1.45% 78.67% 70ms 1.45% runtime.lock2 /usr/local/go/src/runtime/lock_futex.go:61
60ms 1.24% 79.92% 60ms 1.24% runtime.siftdownTimer /usr/local/go/src/runtime/time.go:1124