fix race when starting a service while the agent `serviceManager` is … (#12302)

* fix race when starting a service while the agent `serviceManager` is stopping

* add changelog
This commit is contained in:
Dhia Ayachi 2022-02-10 13:30:49 -05:00 committed by GitHub
parent 80be396bec
commit de7598f064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

3
.changelog/12302.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
Fix a data race when a service is added while the agent is shutting down..
```

View File

@ -1368,14 +1368,14 @@ func (a *Agent) ShutdownAgent() error {
// this should help them to be stopped more quickly // this should help them to be stopped more quickly
a.baseDeps.AutoConfig.Stop() 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) // Stop the service manager (must happen before we take the stateLock to avoid deadlock)
if a.serviceManager != nil { if a.serviceManager != nil {
a.serviceManager.Stop() a.serviceManager.Stop()
} }
// Stop all the checks // Stop all the checks
a.stateLock.Lock()
defer a.stateLock.Unlock()
for _, chk := range a.checkMonitors { for _, chk := range a.checkMonitors {
chk.Stop() chk.Stop()
} }