diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index d766ba09c32..1e9837fbaa3 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -169,13 +169,9 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str if err != nil { return "", fmt.Errorf("watch error:%v for volume %v", err, volumeHandle) } - var watcherClosed bool + ch := watcher.ResultChan() - defer func() { - if !watcherClosed { - watcher.Stop() - } - }() + defer watcher.Stop() for { select { @@ -201,11 +197,7 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str return "", errors.New("volume attachment has been deleted") case watch.Error: - // close the watcher to avoid keeping the watcher too log - watcher.Stop() - watcherClosed = true - // start another cycle - return c.waitForVolumeAttachmentInternal(volumeHandle, attachID, timer, timeout) + klog.Warningf("waitForVolumeAttachmentInternal received watch error: %v", event) } case <-timer.C: diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index f13e53393a9..2e3b177643c 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -221,6 +221,8 @@ func TestAttacherAttach(t *testing.T) { status.AttachError = &storage.VolumeError{ Message: "attacher error", } + errStatus := apierrs.NewInternalError(fmt.Errorf("we got an error")).Status() + fakeWatcher.Error(&errStatus) } else { status.Attached = true }