diff --git a/.changelog/12302.txt b/.changelog/12302.txt new file mode 100644 index 0000000000..8609318a0d --- /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 7e2a7f110a..dd981a459e 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() }