Commit a01f0b4e authored by caiweidong's avatar caiweidong

Bugfix: fix channel leak when stop error

parent e6188f8c
......@@ -161,14 +161,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")
}
......
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