remove panic on double close watch channel (#3223)

This commit is contained in:
Harshavardhana
2020-05-19 14:31:24 -07:00
committed by GitHub
parent 949dd282f9
commit bf731558cd
3 changed files with 5 additions and 24 deletions
+4 -2
View File
@@ -801,8 +801,10 @@ func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
}
go func() {
wg.Wait()
wo.Close()
wg.Wait() // this occurs when all watchers have returned
// we can safely close data and error channels
close(wo.EventInfoChan)
close(wo.ErrorChan)
}()
return wo, nil
+1 -1
View File
@@ -162,7 +162,7 @@ func mainWatch(ctx *cli.Context) error {
fatalIf(err, "Cannot watch on the specified bucket.")
// Initialize.. waitgroup to track the go-routine.
wg := sync.WaitGroup{}
var wg sync.WaitGroup
// Increment wait group to wait subsequent routine.
wg.Add(1)
-21
View File
@@ -93,14 +93,6 @@ func (w *WatchObject) Errors() chan *probe.Error {
return w.ErrorChan
}
// Close the watcher, will stop all goroutines
func (w *WatchObject) Close() {
// Cleanup
close(w.EventInfoChan)
close(w.ErrorChan)
close(w.DoneChan)
}
// Watcher can be used to have one or multiple clients watch for notifications
type Watcher struct {
sessionStartTime time.Time
@@ -137,19 +129,6 @@ func (w *Watcher) Events() chan []EventInfo {
return w.EventInfoChan
}
// Stop watcher
func (w *Watcher) Stop() {
// close all running goroutines
for _, wo := range w.o {
wo.Close()
}
w.wg.Wait()
close(w.ErrorChan)
close(w.EventInfoChan)
}
// Watching returns if the watcher is watching for notifications
func (w *Watcher) Watching() bool {
return (len(w.o) > 0)