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

Fix #10661: docker compose up always kills the containers on second Ctrl-C #11718

Merged
merged 4 commits into from
Apr 14, 2024

Conversation

jsoriano
Copy link
Contributor

@jsoriano jsoriano commented Apr 11, 2024

What I did

Hitting Ctrl-C twice in docker compose up is supposed to immediately kill the containers.
Kill executed on the second Ctrl-C was filtering containers depending on its state. In some
cases the containers can reach an state for what these filters don't get any container, and
the command hangs while printing no container to kill.

Remove this filtering, so it tries to kill any container it finds, independently of their state.

Related issue

Fixes #10661

Kill executed on the second Ctrl-C of docker compose up  was
filtering containers depending on its state. In some cases the
containers can reach an state for what these filters don't get
any container, and the command keeps reporting `no container to
kill`.

Remove this filtering, so it tries to kill any container it
finds, independently of its state.

Fixes docker#10661

Signed-off-by: Jaime Soriano Pastor <[email protected]>
@ndeloof
Copy link
Contributor

ndeloof commented Apr 12, 2024

AFAICT kill on a stopped container will fail

Error response from daemon: cannot kill container: dafcbcd023c1: container dafcbcd023c1c1bbed6b0a35a7e1e2420129672c327519698ef8cbd644fefd06 is not running

would need to ignore such an error, assuming this is the right fix for this race condition

@jsoriano
Copy link
Contributor Author

AFAICT kill on a stopped container will fail

Error response from daemon: cannot kill container: dafcbcd023c1: container dafcbcd023c1c1bbed6b0a35a7e1e2420129672c327519698ef8cbd644fefd06 is not running

You are right, this was briefly showing an error. I have changed the code to use the internal kill method, that doesn't show the progress. And to ignore the returned error.

return s.Kill(context.Background(), project.Name, api.KillOptions{
// Intentionally ignore errors, for cases where some
// of the containers are already stopped.
s.kill(context.Background(), project.Name, api.KillOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not ignore all errors, but only the "not found" one

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 don't find a reliable way to distinguish errors here, as they don't seem to be typed. Should I add the check based on the text of the error? I guess it would be to check if the error message contains is not running.

Also, with the current code, even if it returns the error, it doesn't seem to be doing anything about it. If the kill fails, the loop is still finished and the command hangs if there are still containers running. I could try to fix this too if I add error handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

have you tried using errdefs.IsNotFound(err) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This worked. I also checked errdefs.IsConflict, which happens if one of the containers is already stopped.

Project: project,
})
})
return nil
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 am removing this return, so it is possible now to try to kill the containers again after one kill failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary, I hardly can imagine process could survive a SIGKILL
Also I'm not sure about the potential side-effects doing so, so if you don't mind I'd prefer to be conservative 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.

Well, indeed hopefully no process is going to survive a SIGKILL 🙂 But this is sending requests to kill containers to the docker daemon through HTTP, so there are other things that could fail in the way.

In any case I agree with being conservative and keep previous behaviour, I will revert this.

@ndeloof ndeloof merged commit 7d36164 into docker:main Apr 14, 2024
28 checks passed
@jsoriano
Copy link
Contributor Author

@ndeloof thanks for the reviews and the help on this change. Could you also take a look to #11719? Thanks!

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.

[BUG] docker compose up not returning shell and erroneously detecting error
2 participants