remove panic on double close watch channel (#3223)
This commit is contained in:
+4
-2
@@ -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
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user