Skip to content

Commit

Permalink
close service ring buffers on Pebble shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Aug 11, 2023
1 parent be25405 commit 04de335
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internals/overlord/servstate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ func (m *ServiceManager) doStop(task *state.Task, tomb *tomb.Tomb) error {
if service == nil {
return nil
}
// Close the ringbuffer to signal to consumers (e.g. log forwarding) that
// there are no more logs coming.
defer service.logs.Close()

// Stop service: send SIGTERM, and if that doesn't stop the process in a
// short time, send SIGKILL.
Expand Down Expand Up @@ -284,6 +281,17 @@ func (m *ServiceManager) removeService(name string) {
m.servicesLock.Lock()
defer m.servicesLock.Unlock()

svc, svcExists := m.services[name]
if !svcExists {
return
}
if svc.logs != nil {
err := svc.logs.Close()
if err != nil {
logger.Noticef("Error closing service %q ring buffer: %v", name, err)
}
}

delete(m.services, name)
}

Expand Down
3 changes: 3 additions & 0 deletions internals/overlord/servstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (m *ServiceManager) Stop() {
if err != nil {
logger.Noticef("Cannot stop child process reaper: %v", err)
}
for name := range m.services {
m.removeService(name)
}
}

// NotifyPlanChanged adds f to the list of functions that are called whenever
Expand Down

0 comments on commit 04de335

Please sign in to comment.