Skip to content

Conversation

@giulio93
Copy link
Contributor

@giulio93 giulio93 commented Nov 27, 2025

Motivation

If at least a container of an application is stopped due to any reason, the application status should be failed.
In this way even if other containers are up and running the state of the application state is set as failed, and the user can debug the failed container.

@giulio93 giulio93 requested a review from lucarin91 November 27, 2025 13:21
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch 2 times, most recently from 9be4ebb to 1bfe213 Compare November 27, 2025 13:23
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch 5 times, most recently from dc07a7f to 09691b6 Compare November 28, 2025 08:36
@lucarin91
Copy link
Contributor

we should think of some test for this

@lucarin91 lucarin91 changed the title Add status stopped in container list app status fix: make app failed if a container is stopped Nov 28, 2025
containerState: []container.ContainerState{container.StateRunning, container.StateDead, container.StateRemoving, container.StateRestarting, container.StateExited},
want: StatusFailed,
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a test for the new check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created as status failed!
i've also added statusMessage string example inspired by some real cases

@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch from 3db2a77 to 0243557 Compare November 28, 2025 09:13
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch from 0243557 to 2549af2 Compare December 5, 2025 11:37
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch from 2549af2 to a09d652 Compare December 5, 2025 15:02
continue
}
if slices.ContainsFunc(s, func(v containerStateInfo) bool {
return v.State == StatusStopped && strings.Contains(v.StatusMessage, "Exited (0)")
Copy link
Contributor

@lucarin91 lucarin91 Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should account for all exit codes that aren't signals, so everything that is less than 128

If you write an app with Python-like

exit(1)

You say that this isn't a fail, which in fact it is, because the app exits right after be started.

}
appsStatusMap[appPath] = append(appsStatusMap[appPath], StatusFromDockerState(c.State))
appsStatusMap[appPath] = append(appsStatusMap[appPath], containerStateInfo{
State: StatusFromDockerState(c.State),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you update this mapping function and don't account for the status message there? If a container exited with anything that isn't 128 + 9 we could consider that a failing state, because it means that the process exited without Docker killing it.

@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch 4 times, most recently from 9b7128a to fbcc770 Compare December 11, 2025 15:33
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch from fbcc770 to fe0cced Compare December 11, 2025 15:43
@giulio93 giulio93 requested a review from lucarin91 December 15, 2025 09:06
continue
}
if slices.ContainsFunc(s, func(v Status) bool { return v == StatusStopping }) {
if slices.ContainsFunc(s, func(v containerState) bool { return v.Status == StatusStopped && checkExitCode(v) }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in a previous review

Why don't you update this mapping function and don't account for the status message there? If a container exited with anything that isn't 128 + 9 we could consider that a failing state, because it means that the process exited without Docker killing it.

I would like to move the parsing function checkExitCode to the StatusFromDockerState mapping function. I think it is clearer to have a single function for mapping docker container status to our app status, instead of adding a special check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've finally change it to a check bool function, that parse and check that the code is grater than 128, so we now if it was killed or it failed

return []Status{StatusStarting, StatusRunning, StatusStopping, StatusStopped, StatusFailed}
}

func checkExitCode(statusMessage string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure which is the meaning of checkExitCode. I would rename this function to

Suggested change
func checkExitCode(statusMessage string) bool {
func parseExitCode(statusMessage string) (int, error) {

And use it above in the following way

    if code, err := parseExitCode(statusMessage); err != nil {
         slog.Warn("Failed to parse exit code from status message", slog.String("statusMessage", statusMessage), slog.String("error", err.Error())
    } else if code >= 0 && code < 128 {
		    return StatusFailed
    } 
    return StatusStopped

slog.Error("Failed to parse exit code from status message", slog.String("statusMessage", statusMessage), slog.String("error", err.Error()))
return false
}
if exitCode >= 0 && exitCode < 128 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that 128 should be included, i.e., https://tldp.org/LDP/abs/html/exitcodes.html. If we want to consider a failing status, everything that isn't a signal that should include 128, signals start from 128+n, and the signal number cannot be 0.

@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch 8 times, most recently from 339d18c to 09a7e8b Compare December 16, 2025 16:23
@giulio93 giulio93 force-pushed the add_stopped_state_to_app_status branch from 09a7e8b to acba544 Compare December 16, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants