From 0d86e802be207d9ac547f8b93d21d6271ee5c0d6 Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Tue, 26 May 2020 10:01:49 +0200 Subject: [PATCH] Stop all watches before shuting down anything dring shutdown. (#7526) This will prevent watches from being triggered. ```changelog * fix(agent): stop all watches before shuting down ``` --- agent/agent.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 76f07e6dad..8e419e3b93 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1035,13 +1035,18 @@ func (a *Agent) serveHTTP(srv *HTTPServer) error { } } +// stopAllWatches stops all the currently running watches +func (a *Agent) stopAllWatches() { + for _, wp := range a.watchPlans { + wp.Stop() + } +} + // reloadWatches stops any existing watch plans and attempts to load the given // set of watches. func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error { // Stop the current watches. - for _, wp := range a.watchPlans { - wp.Stop() - } + a.stopAllWatches() a.watchPlans = nil // Return if there are no watches now. @@ -1743,6 +1748,8 @@ func (a *Agent) ShutdownAgent() error { return nil } a.logger.Info("Requesting shutdown") + // Stop the watches to avoid any notification/state change during shutdown + a.stopAllWatches() // Stop the service manager (must happen before we take the stateLock to avoid deadlock) if a.serviceManager != nil {