refact(controller): Decouple listeners/servers shutdown from Worker

In general, these changes were introduced in the same vein of the
changes to controller `startListeners`.

Specifically, these changes also decouple the Controller and the Worker
shutdown processes. Currently, a call to `stopListeners` on an instance
that is running as both a Controller and a Worker would stop the
listeners for both.

Lastly, we also add unit/integration tests to the shutdown code.
This commit is contained in:
Hugo Vieira committed 2022-03-25 15:04:23 +00:00
1 parent d438a6d2dd
commit eebdfb88dc
9 files changed
+572 -72

No files matched your search

+3 -3
View File
@@ -352,15 +352,15 @@ func (c *Controller) registerSessionConnectionCleanupJob() error {
return nil
}
func (c *Controller) Shutdown(serversOnly bool) error {
func (c *Controller) Shutdown() error {
const op = "controller.(Controller).Shutdown"
if !c.started.Load() {
event.WriteSysEvent(context.TODO(), op, "already shut down, skipping")
}
defer c.started.Store(false)
c.baseCancel()
if err := c.stopListeners(serversOnly); err != nil {
return fmt.Errorf("error stopping controller listeners: %w", err)
if err := c.stopServersAndListeners(); err != nil {
return fmt.Errorf("error stopping controller servers and listeners: %w", err)
}
c.schedulerWg.Wait()
c.tickerWg.Wait()