Fix #11710: Avoid to try to close channel twice after hitting Ctrl-C on compose up #11719
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
atomic.Bool
forisTerminated
. Not sure if really needed, but looks safer, as it is a value that is written and read from different goroutines.Up
is called as part of other commands.context.WithoutCancel(ctx)
in the cases wherecontext.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.