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

Avoid data race by calling forceCompState only on commandRuntime.Run #3537

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pkg/component/runtime/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (c *commandRuntime) startWatcher(info *process.Info, comm Communicator) {
go func() {
err := comm.WriteConnInfo(info.Stdin)
if err != nil {
c.forceCompState(client.UnitStateFailed, fmt.Sprintf("Failed: failed to provide connection information to spawned pid '%d': %s", info.PID, err))
_, _ = c.logErr.Write([]byte(fmt.Sprintf("Failed: failed to provide connection information to spawned pid '%d': %s", info.PID, err)))
// kill instantly
_ = info.Kill()
} else {
Expand Down
11 changes: 7 additions & 4 deletions pkg/component/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2481,18 +2481,21 @@ func TestManager_FakeInput_RestartsOnMissedCheckins(t *testing.T) {
return
case state := <-sub.Ch():
t.Logf("component state changed: %+v", state)
if state.State == client.UnitStateStarting || state.State == client.UnitStateHealthy {

switch state.State {
case client.UnitStateStarting:
case client.UnitStateHealthy:
// starting and healthy are allowed
} else if state.State == client.UnitStateDegraded {
case client.UnitStateDegraded:
// should go to degraded first
wasDegraded = true
} else if state.State == client.UnitStateFailed {
case client.UnitStateFailed:
if wasDegraded {
subErrCh <- nil
} else {
subErrCh <- errors.New("should have been degraded before failed")
}
} else {
default:
subErrCh <- fmt.Errorf("unknown component state: %v", state.State)
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/component/runtime/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ func (s *ComponentState) cleanupStopped() bool {
return cleaned
}

// forceState force updates the state for the entire component, forcing that state on all units.
// forceState force updates the state for the entire component, forcing that
// state on all units. It returns true if either the component state or any of
// the units state changed, false otherwise.
func (s *ComponentState) forceState(state client.UnitState, msg string) bool {
changed := false
if s.State != state || s.Message != msg {
Expand Down
Loading