diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 3528dc3b833..233c23077e0 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -491,14 +491,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 @@ -507,6 +507,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) } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go index afb24876adf..04057149319 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go @@ -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(): }