From 0508bea9b66fab3dc5892098c8ffb3a6d9462360 Mon Sep 17 00:00:00 2001 From: caiweidong Date: Thu, 6 Jun 2019 14:47:36 +0800 Subject: [PATCH] Fix keep the watcher open for too long --- pkg/volume/csi/csi_attacher.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 9b1bd2a58fc..a209947ee50 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -169,9 +169,13 @@ 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 watcher.Stop() + defer func() { + if !watcherClosed { + watcher.Stop() + } + }() for { select { @@ -197,8 +201,11 @@ 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 - c.waitForVolumeAttachmentInternal(volumeHandle, attachID, timer, timeout) + return c.waitForVolumeAttachmentInternal(volumeHandle, attachID, timer, timeout) } case <-timer.C: