Fix issue where compose logs
doesn't exit when all running containers have been stopped
#10181
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.
Signed-off-by: Laura Brehm laurabrehm@hey.com
Currently, the issue exists where, with a
compose.yaml
such asif one runs:
compose create
compose start foo
compose logs -f
and in a separate tab run:
compose stop foo
the logs hang, even though all containers have stopped. This does not align with Compose v1 behaviour, and leads to inconsistent behavior, such as:
If there is only one service defined in a Compose file:
and then run:
compose up -d
compose logs -f
and in a separate tab run:
compose restart foo
the logs will exit, since only 1 container is expected (
len(expected) == 1
) to exist and the container exit during the restart.However, if there are two services defined, even if one is stopped, running
compose restart [running service container]
does not cause the logs to exit, because even though the other container is stopped,len(expected) == 2
, and when the container restarts, logs are still streamed.(This also has to do with our current logic to detect whether a container will restart – inspecting the container after the
die
event and checking whetherinspected.State.Restarting == true
, which seems broken (always returns false, maybe due to race conditions between when we receive thedie
event and make the container inspect call). However, I have no idea how to check whether a container will restart other than waiting for a bit before closing the stream after adie
event to see if we receive arestart
event).What I did
Adjust theexpected
calculation, to only account for currently running containers, to align with v1 behavior.I played around with other ways of not exiting logs if a container is restarting instead of stopping, but I'll make another draft PR with that to get some discussion going.Made the changes in
pkg/compose/logs.go
to filter containers passed towatch
to only account for running containers (when using-f
withcompose logs
), but keep the same logic elsewhere (like incompose start
).Related issue
(not mandatory) A picture of a cute animal, if possible in relation to what you did