Unverified Commit 032b4d39 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #77304 from cwdsuzhou/fix_leak_when_stop_error

Bugfix: fix chan leak when stop error
parents 4036097e a01f0b4e
...@@ -155,14 +155,17 @@ func (w *Watcher) Stop() error { ...@@ -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")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment