Correctly drain timer

This commit is contained in:
Mikhail Mazurskiy 2021-04-26 15:01:33 +10:00
parent 3e71ecc6b3
commit 5b42681840
No known key found for this signature in database
GPG Key ID: FA7917C48932DD55
2 changed files with 6 additions and 2 deletions

View File

@ -475,14 +475,14 @@ func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(volumeHandle, at
clock = &clock.RealClock{}
)
backoffMgr := wait.NewExponentialBackoffManager(initBackoff, maxBackoff, resetDuration, backoffFactor, jitter, clock)
defer backoffMgr.Backoff().Stop()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
for {
t := backoffMgr.Backoff()
select {
case <-backoffMgr.Backoff().C():
case <-t.C():
successful, err := verifyStatus()
if err != nil {
return err
@ -491,6 +491,7 @@ func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(volumeHandle, at
return nil
}
case <-ctx.Done():
t.Stop()
klog.Error(log("%s timeout after %v [volume=%v; attachment.ID=%v]", operation, timeout, volumeHandle, attachID))
return fmt.Errorf("%s timeout for volume %v", operation, volumeHandle)
}

View File

@ -166,6 +166,9 @@ func BackoffUntil(f func(), backoff BackoffManager, sliding bool, stopCh <-chan
// of every loop to prevent extra executions of f().
select {
case <-stopCh:
if !t.Stop() {
<-t.C()
}
return
case <-t.C():
}