From de7598f064501d324872ede496b2f0a6afd36f54 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Thu, 10 Feb 2022 13:30:49 -0500 Subject: [PATCH] =?UTF-8?q?fix=20race=20when=20starting=20a=20service=20wh?= =?UTF-8?q?ile=20the=20agent=20`serviceManager`=20is=20=E2=80=A6=20(#12302?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix race when starting a service while the agent `serviceManager` is stopping * add changelog --- .changelog/12302.txt | 3 +++ agent/agent.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changelog/12302.txt diff --git a/.changelog/12302.txt b/.changelog/12302.txt new file mode 100644 index 000000000..8609318a0 --- /dev/null +++ b/.changelog/12302.txt @@ -0,0 +1,3 @@ +```release-note:bug +Fix a data race when a service is added while the agent is shutting down.. +``` diff --git a/agent/agent.go b/agent/agent.go index 7e2a7f110..dd981a459 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1368,14 +1368,14 @@ func (a *Agent) ShutdownAgent() error { // this should help them to be stopped more quickly a.baseDeps.AutoConfig.Stop() + a.stateLock.Lock() + defer a.stateLock.Unlock() // Stop the service manager (must happen before we take the stateLock to avoid deadlock) if a.serviceManager != nil { a.serviceManager.Stop() } // Stop all the checks - a.stateLock.Lock() - defer a.stateLock.Unlock() for _, chk := range a.checkMonitors { chk.Stop() }