diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 8ae8f8c3d..88d12f73b 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -24,6 +24,8 @@ type Controller struct { config *Config reporter reporter.Reporter tracer *tracer.Tracer + + cancelFunc context.CancelFunc } // New creates a new controller @@ -48,6 +50,8 @@ func (c *Controller) Start(ctx context.Context) error { intervals := times.New(c.config.ReporterInterval, c.config.MonitorInterval, c.config.ProbabilisticInterval) + ctx, c.cancelFunc = context.WithCancel(ctx) + // Start periodic synchronization with the realtime clock times.StartRealtimeSync(ctx, c.config.ClockSyncInterval) @@ -151,6 +155,10 @@ func (c *Controller) Start(ctx context.Context) error { // Shutdown stops the controller func (c *Controller) Shutdown() { log.Info("Stop processing ...") + if c.cancelFunc != nil { + c.cancelFunc() + } + if c.reporter != nil { c.reporter.Stop() }