From eed3b66d98b3f30f52571511d57ee1d2901288b8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 17 Mar 2021 16:37:13 -0700 Subject: [PATCH] dsync: use refresh timer properly to avoid leaks (#11820) timer pattern should always involve a 'Stop()/Reset()' otherwise `time.NewTimer(duration).C` will always leak. --- pkg/dsync/drwmutex.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/dsync/drwmutex.go b/pkg/dsync/drwmutex.go index 593a26b41..01efd412b 100644 --- a/pkg/dsync/drwmutex.go +++ b/pkg/dsync/drwmutex.go @@ -220,11 +220,17 @@ func (dm *DRWMutex) startContinousLockRefresh(lockLossCallback func(), id, sourc go func() { defer cancel() + + refreshTimer := time.NewTimer(drwMutexRefreshInterval) + defer refreshTimer.Stop() + for { select { case <-ctx.Done(): return - case <-time.NewTimer(drwMutexRefreshInterval).C: + case <-refreshTimer.C: + refreshTimer.Reset(drwMutexRefreshInterval) + refreshed, err := refresh(ctx, dm.clnt, id, source, quorum, dm.Names...) if err == nil && !refreshed { if lockLossCallback != nil {