mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #77304 from cwdsuzhou/fix_leak_when_stop_error
Bugfix: fix chan leak when stop error
This commit is contained in:
commit
032b4d39c6
@ -155,14 +155,17 @@ func (w *Watcher) Stop() error {
|
|||||||
close(w.stopCh)
|
close(w.stopCh)
|
||||||
|
|
||||||
c := make(chan struct{})
|
c := make(chan struct{})
|
||||||
|
var once sync.Once
|
||||||
|
closeFunc := func() { close(c) }
|
||||||
go func() {
|
go func() {
|
||||||
defer close(c)
|
defer once.Do(closeFunc)
|
||||||
w.wg.Wait()
|
w.wg.Wait()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-c:
|
case <-c:
|
||||||
case <-time.After(11 * time.Second):
|
case <-time.After(11 * time.Second):
|
||||||
|
once.Do(closeFunc)
|
||||||
return fmt.Errorf("timeout on stopping watcher")
|
return fmt.Errorf("timeout on stopping watcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user