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.
This commit is contained in:
Aditya Manthramurthy 2022-05-18 15:37:58 -07:00 committed by GitHub
parent 6cfb1cb6fd
commit 9aadd725d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

View file

@ -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)
}
}

View file

@ -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.

View file

@ -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
}

View file

@ -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)
}
}
}()