Skip to content

Fix #11710: Avoid to try to close channel twice after hitting Ctrl-C on compose up#11719

Merged
ndeloof merged 5 commits intodocker:mainfrom
jsoriano:compose-up-close-panic
Apr 20, 2024
Merged

Fix #11710: Avoid to try to close channel twice after hitting Ctrl-C on compose up#11719
ndeloof merged 5 commits intodocker:mainfrom
jsoriano:compose-up-close-panic

Conversation

@jsoriano
Copy link
Contributor

What I did

Try to fix a panic happening when hitting Ctrl-C on docker compose up. I could barely reproduce the issue, so not sure if this change fixes it, but I think that at least it can improve the situation.

I think that the channel should not be closed in the graceful termination. If it successfully stops the containers, then start will also finish and the channel can be closed then. If the graceful termination fails to stop the containers and closes the channel, then it will close the channel, finalizing the goroutine and preventing further Ctrl-C to do anything.

So I am removing the close in the graceful termination, and doing it in all cases once start has finished.

Apart of that I am doing some other changes around there:

  • Use atomic.Bool for isTerminated. Not sure if really needed, but looks safer, as it is a value that is written and read from different goroutines.
  • Cleanup of signal handling, what can be useful if Up is called as part of other commands.
  • Use context.WithoutCancel(ctx) in the cases where context.Background() was being used. This way the rest of the context information is propagated.

Happy to move these changes to different PRs if neccesary.

Related issue

Fixes #11710.

Signed-off-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Signed-off-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
@jsoriano
Copy link
Contributor Author

@ndeloof is there anything pending to merge this PR?

@ndeloof ndeloof enabled auto-merge (rebase) April 18, 2024 09:31
auto-merge was automatically disabled April 18, 2024 09:38

Rebase failed

@ndeloof
Copy link
Contributor

ndeloof commented Apr 19, 2024

Please rebase your branch then we can merge

@ndeloof ndeloof enabled auto-merge (squash) April 20, 2024 06:02
@ndeloof ndeloof merged commit 5682480 into docker:main Apr 20, 2024
temenuzhka-thede pushed a commit to temenuzhka-thede/compose that referenced this pull request Sep 17, 2024
…trl-C on compose up (docker#11719)

Ensure done channel is closed only once

Signed-off-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
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] Channel double close panic on Ctrl-C during up

2 participants