mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
Clean up any watch monitors associated with a failed AddCheck
This commit is contained in:
parent
6a257f242e
commit
e50f0e6722
@ -1789,6 +1789,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
|
|||||||
// Add to the local state for anti-entropy
|
// Add to the local state for anti-entropy
|
||||||
err := a.state.AddCheck(check, token)
|
err := a.state.AddCheck(check, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
a.cancelCheckMonitors(check.CheckID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1814,6 +1815,21 @@ func (a *Agent) RemoveCheck(checkID types.CheckID, persist bool) error {
|
|||||||
a.checkLock.Lock()
|
a.checkLock.Lock()
|
||||||
defer a.checkLock.Unlock()
|
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
|
// Stop any monitors
|
||||||
delete(a.checkReapAfter, checkID)
|
delete(a.checkReapAfter, checkID)
|
||||||
if check, ok := a.checkMonitors[checkID]; ok {
|
if check, ok := a.checkMonitors[checkID]; ok {
|
||||||
@ -1836,16 +1852,6 @@ func (a *Agent) RemoveCheck(checkID types.CheckID, persist bool) error {
|
|||||||
check.Stop()
|
check.Stop()
|
||||||
delete(a.checkDockers, checkID)
|
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.
|
// updateTTLCheck is used to update the status of a TTL check via the Agent API.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user