From 9aadd725d25a7072a1d6abad874b316a5774faa8 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Wed, 18 May 2022 15:37:58 -0700 Subject: [PATCH] Avoid calling .Reset() on active timer (#14941) .Reset() documentation states: For a Timer created with NewTimer, Reset should be invoked only on stopped or expired timers with drained channels. This change is just to comply with this requirement as there might be some runtime dependent situation that might lead to unexpected behavior. --- cmd/bucket-replication-stats.go | 8 +++----- cmd/mrf.go | 2 +- cmd/site-replication.go | 10 ++++------ internal/dsync/drwmutex.go | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/bucket-replication-stats.go b/cmd/bucket-replication-stats.go index 70ebb642f..a3174fd51 100644 --- a/cmd/bucket-replication-stats.go +++ b/cmd/bucket-replication-stats.go @@ -169,19 +169,17 @@ func (r *ReplicationStats) loadInitialReplicationMetrics(ctx context.Context) { ) outer: for { - rTimer.Reset(time.Minute) select { case <-ctx.Done(): return case <-rTimer.C: dui, err = loadDataUsageFromBackend(GlobalContext, newObjectLayerFn()) - if err != nil { - continue - } // If LastUpdate is set, data usage is available. - if !dui.LastUpdate.IsZero() { + if err == nil && !dui.LastUpdate.IsZero() { break outer } + + rTimer.Reset(time.Minute) } } diff --git a/cmd/mrf.go b/cmd/mrf.go index 2e3081d1e..831adb838 100644 --- a/cmd/mrf.go +++ b/cmd/mrf.go @@ -190,12 +190,12 @@ func (m *mrfState) healRoutine() { } for { - idler.Reset(mrfInfoResetInterval) select { case <-m.ctx.Done(): return case <-idler.C: m.resetMRFInfoIfNoPendingOps() + idler.Reset(mrfInfoResetInterval) case setInfo := <-m.setReconnectEvent: // Get the list of objects related the er.set // to which the connected disk belongs. diff --git a/cmd/site-replication.go b/cmd/site-replication.go index e6a86362f..a05255570 100644 --- a/cmd/site-replication.go +++ b/cmd/site-replication.go @@ -3330,19 +3330,17 @@ func (c *SiteReplicationSys) startHealRoutine(ctx context.Context, objAPI Object defer healTimer.Stop() for { - healTimer.Reset(siteHealTimeInterval) - select { case <-healTimer.C: c.RLock() enabled := c.enabled c.RUnlock() - if !enabled { - continue + if enabled { + c.healIAMSystem(ctx, objAPI) // heal IAM system first + c.healBuckets(ctx, objAPI) // heal buckets subsequently } + healTimer.Reset(siteHealTimeInterval) - c.healIAMSystem(ctx, objAPI) // heal IAM system first - c.healBuckets(ctx, objAPI) // heal buckets subsequently case <-ctx.Done(): return } diff --git a/internal/dsync/drwmutex.go b/internal/dsync/drwmutex.go index 9cd077fd8..72f7aabbe 100644 --- a/internal/dsync/drwmutex.go +++ b/internal/dsync/drwmutex.go @@ -255,8 +255,6 @@ func (dm *DRWMutex) startContinousLockRefresh(lockLossCallback func(), id, sourc defer refreshTimer.Stop() for { - refreshTimer.Reset(dm.refreshInterval) - select { case <-ctx.Done(): return @@ -271,6 +269,8 @@ func (dm *DRWMutex) startContinousLockRefresh(lockLossCallback func(), id, sourc } return } + + refreshTimer.Reset(dm.refreshInterval) } } }()