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
```
This commit is contained in:
Pierre Souchay 2020-05-26 10:01:49 +02:00 committed by R.B. Boyer
parent 66612e5dc6
commit 0d86e802be
1 changed files with 10 additions and 3 deletions

View File

@ -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 {