diff --git a/command/agent/agent.go b/command/agent/agent.go index 7e4ce4c2b3..16d1b741a5 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -938,7 +938,7 @@ func (a *Agent) recallCheckState(check *structs.HealthCheck) error { // Check if the state has expired if time.Now().Unix() >= p.Expires { a.logger.Printf("[DEBUG] agent: check state expired for %q, not restoring", check.CheckID) - return nil + return a.purgeCheckState(check.CheckID) } // Restore the fields from the state diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index c5439383a2..97cfa98684 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -1350,7 +1350,7 @@ func TestAgent_loadChecks_checkFails(t *testing.T) { } } -func TestAgent_persistCheckStatus(t *testing.T) { +func TestAgent_persistCheckState(t *testing.T) { config := nextConfig() dir, agent := makeAgent(t, config) defer os.RemoveAll(dir) @@ -1433,6 +1433,12 @@ func TestAgent_recallCheckState(t *testing.T) { t.Fatalf("bad: %#v", health) } + // Should have purged the state + file := filepath.Join(agent.config.DataDir, checksDir, stringHash("check1")) + if _, err := os.Stat(file); !os.IsNotExist(err) { + t.Fatalf("should have purged state") + } + // Set a TTL which will not expire before we check it check.TTL = time.Minute err = agent.persistCheckState(check, structs.HealthPassing, "yup")