Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servstate: test stability improvements #266

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions internals/overlord/servstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,14 @@ func (m *ServiceManager) SetServiceArgs(serviceArgs map[string][]string) error {
return m.appendLayer(newLayer)
}

// servicesToStop returns a slice of service names to stop, in dependency order.
// servicesToStop is used during service manager shutdown to cleanly terminate
flotter marked this conversation as resolved.
Show resolved Hide resolved
// all running services. Running services include both services in the
// stateRunning and stateBackoff, since a service in backoff state can start
// running once the timeout expires, which creates a race on service manager
// exit. If it starts just before, it would continue to run after the service
// manager is terminated. If it starts just after (before the main process
// exits), it would generate a runtime error as the reaper would already be dead.
// This function returns a slice of service names to stop, in dependency order.
func servicesToStop(m *ServiceManager) ([]string, error) {
releasePlan, err := m.acquirePlan()
if err != nil {
Expand All @@ -568,15 +575,15 @@ func servicesToStop(m *ServiceManager) ([]string, error) {
return nil, err
}

// Filter down to only those that are running.
// Filter down to only those that are running or in backoff
m.servicesLock.Lock()
defer m.servicesLock.Unlock()
var running []string
var notStopped []string
for _, name := range stop {
s := m.services[name]
if s != nil && s.state == stateRunning {
running = append(running, name)
if s != nil && (s.state == stateRunning || s.state == stateBackoff) {
flotter marked this conversation as resolved.
Show resolved Hide resolved
notStopped = append(notStopped, name)
}
}
return running, nil
return notStopped, nil
}
Loading
Loading