From b63db8b4111e4859a9870ba8dcd9ea124b78fb04 Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Wed, 23 Aug 2023 10:04:19 -0500 Subject: [PATCH] Backport of bug: prevent go routine leakage due to existing DeferCheck into release/1.16.x (#18565) * backport of commit 06d4c72f682881c78265248fb749ebfd5cc365b8 * backport of commit 42c37bb2c1e4d8eac8078f17c16b8e6797baa446 --------- Co-authored-by: cskh --- .changelog/18558.txt | 3 +++ agent/local/state.go | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 .changelog/18558.txt 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