Skip to content

Commit

Permalink
[watchmanager] Do not leak tickers in stopped watches (#2972)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis authored Dec 3, 2020
1 parent 38f0545 commit 9f0944a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cluster/etcd/watchmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9f0944a

Please sign in to comment.