Merge pull request #77304 from cwdsuzhou/fix_leak_when_stop_error

Bugfix: fix chan leak when stop error
This commit is contained in:
Kubernetes Prow Robot 2019-05-14 18:24:55 -07:00 committed by GitHub
commit 032b4d39c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -155,14 +155,17 @@ func (w *Watcher) Stop() error {
close(w.stopCh)
c := make(chan struct{})
var once sync.Once
closeFunc := func() { close(c) }
go func() {
defer close(c)
defer once.Do(closeFunc)
w.wg.Wait()
}()
select {
case <-c:
case <-time.After(11 * time.Second):
once.Do(closeFunc)
return fmt.Errorf("timeout on stopping watcher")
}