From db1d477592984caa0cc250648370583b03f17531 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 18 Jul 2017 16:54:20 -0500 Subject: [PATCH] Clean up any watch monitors associated with a failed AddCheck --- agent/agent.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index c2529bb99..7b2fd0d47 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1789,6 +1789,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType, // Add to the local state for anti-entropy err := a.state.AddCheck(check, token) if err != nil { + a.cancelCheckMonitors(check.CheckID) return err } @@ -1814,6 +1815,21 @@ func (a *Agent) RemoveCheck(checkID types.CheckID, persist bool) error { a.checkLock.Lock() defer a.checkLock.Unlock() + a.cancelCheckMonitors(checkID) + + if persist { + if err := a.purgeCheck(checkID); err != nil { + return err + } + if err := a.purgeCheckState(checkID); err != nil { + return err + } + } + a.logger.Printf("[DEBUG] agent: removed check %q", checkID) + return nil +} + +func (a *Agent) cancelCheckMonitors(checkID types.CheckID) { // Stop any monitors delete(a.checkReapAfter, checkID) if check, ok := a.checkMonitors[checkID]; ok { @@ -1836,16 +1852,6 @@ func (a *Agent) RemoveCheck(checkID types.CheckID, persist bool) error { check.Stop() delete(a.checkDockers, checkID) } - if persist { - if err := a.purgeCheck(checkID); err != nil { - return err - } - if err := a.purgeCheckState(checkID); err != nil { - return err - } - } - a.logger.Printf("[DEBUG] agent: removed check %q", checkID) - return nil } // updateTTLCheck is used to update the status of a TTL check via the Agent API.