Merge pull request #79113 from tedyu/stop-w-detach

Close watcher early for volume detachment
This commit is contained in:
Kubernetes Prow Robot 2019-07-12 06:31:18 -07:00 committed by GitHub
commit 9915047d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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