diff --git a/.changelog/18558.txt b/.changelog/18558.txt new file mode 100644 index 000000000..9c2b9b44b --- /dev/null +++ b/.changelog/18558.txt @@ -0,0 +1,3 @@ +```release-note:bug +check: prevent go routine leakage when existing Defercheck of same check id is not nil +``` diff --git a/agent/local/state.go b/agent/local/state.go index 3e43ddc9a..6cd5b0c82 100644 --- a/agent/local/state.go +++ b/agent/local/state.go @@ -838,6 +838,12 @@ func (l *State) setCheckStateLocked(c *CheckState) { existing := l.checks[id] if existing != nil { c.InSync = c.Check.IsSame(existing.Check) + // If the existing check has a Defercheck, it needs to be + // assigned to the new check + if existing.DeferCheck != nil && c.DeferCheck == nil { + c.DeferCheck = existing.DeferCheck + c.InSync = false + } } l.checks[id] = c