Clean up any watch monitors associated with a failed AddCheck

This commit is contained in:
Preetha Appan 2017-07-18 16:54:20 -05:00
parent 6a257f242e
commit e50f0e6722
1 changed files with 16 additions and 10 deletions

View File

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