Make Worker.Shutdown() synchronous (#58)
Previously, a WaitGroup was used to track executing ShardConsumers and prevent Worker.Shutdown() from returning until all ShardConsumers had completed. Unfortunately, it was possible for Shutdown() to race with the eventLoop(), leading to a situation where Worker.Shutdown() returns while a ShardConsumer is still executing. Now, we increment the WaitGroup to keep track the eventLoop() as well as the ShardConsumers. This prevents shutdown from returning until all background go-routines have completed. Signed-off-by: Daniel Ferstay <dferstay@splunk.com>
This commit is contained in:
parent
6c9e594751
commit
a35f4960a8
1 changed files with 6 additions and 2 deletions
|
|
@ -115,8 +115,12 @@ func (w *Worker) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Starting worker event loop.")
|
log.Infof("Starting worker event loop.")
|
||||||
// entering event loop
|
w.waitGroup.Add(1)
|
||||||
go w.eventLoop()
|
go func() {
|
||||||
|
defer w.waitGroup.Done()
|
||||||
|
// entering event loop
|
||||||
|
w.eventLoop()
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue