From 9f0944a63ed83438c0c15b722e11a3cfe2651e68 Mon Sep 17 00:00:00 2001 From: Vytenis Darulis Date: Wed, 2 Dec 2020 20:37:53 -0500 Subject: [PATCH] [watchmanager] Do not leak tickers in stopped watches (#2972) --- src/cluster/etcd/watchmanager/manager.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cluster/etcd/watchmanager/manager.go b/src/cluster/etcd/watchmanager/manager.go index 9d5837e899..0ebba605e4 100644 --- a/src/cluster/etcd/watchmanager/manager.go +++ b/src/cluster/etcd/watchmanager/manager.go @@ -25,9 +25,9 @@ import ( "fmt" "time" + "github.com/uber-go/tally" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/uber-go/tally" "go.uber.org/zap" ) @@ -96,7 +96,8 @@ func (w *manager) watchChanWithTimeout(key string, rev int64) (clientv3.WatchCha } func (w *manager) Watch(key string) { - ticker := time.Tick(w.opts.WatchChanCheckInterval()) //nolint: megacheck + ticker := time.NewTicker(w.opts.WatchChanCheckInterval()) + defer ticker.Stop() var ( revOverride int64 @@ -163,7 +164,7 @@ func (w *manager) Watch(key string) { w.logger.Error("received notification for key, but failed to get value", zap.String("key", key), zap.Error(err)) } - case <-ticker: + case <-ticker.C: if w.tickAndStopFn(key) { w.logger.Info("watch on key ended", zap.String("key", key)) return