Skip to content

Commit

Permalink
obtain lock before reading ServiceManager.services
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Aug 15, 2023
1 parent 97c4681 commit 8863487
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internals/overlord/servstate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ func (m *ServiceManager) serviceForStop(task *state.Task, name string) *serviceD
func (m *ServiceManager) removeService(name string) {
m.servicesLock.Lock()
defer m.servicesLock.Unlock()
m.removeServiceInternal(name)
}

// not concurrency-safe, please lock m.servicesLock before calling
func (m *ServiceManager) removeServiceInternal(name string) {
svc, svcExists := m.services[name]
if !svcExists {
return
Expand Down
6 changes: 5 additions & 1 deletion internals/overlord/servstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ func (m *ServiceManager) Stop() {
if err != nil {
logger.Noticef("Cannot stop child process reaper: %v", err)
}

// Close all the service ringbuffers
m.servicesLock.Lock()
defer m.servicesLock.Unlock()
for name := range m.services {
m.removeService(name)
m.removeServiceInternal(name)
}
}

Expand Down

0 comments on commit 8863487

Please sign in to comment.