From 005065f8fc9895c3ca73ea905727b168bc5c88fc Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Mon, 17 Jun 2019 15:09:40 -0700 Subject: [PATCH] Close watcher early for volume detachment --- pkg/volume/csi/csi_attacher.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 22640946773..c6ef71de210 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -492,8 +492,13 @@ func (c *csiAttacher) waitForVolumeDetachmentInternal(volumeHandle, attachID str if err != nil { return fmt.Errorf("watch error:%v for volume %v", err, volumeHandle) } + var watcherClosed bool ch := watcher.ResultChan() - defer watcher.Stop() + defer func() { + if !watcherClosed { + watcher.Stop() + } + }() for { select { @@ -518,8 +523,10 @@ func (c *csiAttacher) waitForVolumeDetachmentInternal(volumeHandle, attachID str return nil case watch.Error: + watcher.Stop() + watcherClosed = true // start another cycle - c.waitForVolumeDetachmentInternal(volumeHandle, attachID, timer, timeout) + return c.waitForVolumeDetachmentInternal(volumeHandle, attachID, timer, timeout) } case <-timer.C: