mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #78754 from cwdsuzhou/June/csi_attach_close_chan
Avoid to keep the watcher open for too long
This commit is contained in:
commit
e46b9ca656
@ -169,9 +169,13 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("watch error:%v for volume %v", err, volumeHandle)
|
return "", fmt.Errorf("watch error:%v for volume %v", err, volumeHandle)
|
||||||
}
|
}
|
||||||
|
var watcherClosed bool
|
||||||
ch := watcher.ResultChan()
|
ch := watcher.ResultChan()
|
||||||
defer watcher.Stop()
|
defer func() {
|
||||||
|
if !watcherClosed {
|
||||||
|
watcher.Stop()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -197,8 +201,11 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str
|
|||||||
return "", errors.New("volume attachment has been deleted")
|
return "", errors.New("volume attachment has been deleted")
|
||||||
|
|
||||||
case watch.Error:
|
case watch.Error:
|
||||||
|
// close the watcher to avoid keeping the watcher too log
|
||||||
|
watcher.Stop()
|
||||||
|
watcherClosed = true
|
||||||
// start another cycle
|
// start another cycle
|
||||||
c.waitForVolumeAttachmentInternal(volumeHandle, attachID, timer, timeout)
|
return c.waitForVolumeAttachmentInternal(volumeHandle, attachID, timer, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
|
Loading…
Reference in New Issue
Block a user