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
logs -f blocks forever when container is stopped #7020
Comments
Does it start streaming the logs if the container is started and you are still following? |
@crosbymichael when it's started, it behaves as expected: the streaming stops when the container stops. The issue appears when the container is already stopped in the moment of the |
Ok, now I see. It will block waiting for the container to start, but the container won't start again because it has already stopped. This is working as expected. But even when I remove the container it keeps blocked waiting for a stream that will never come, because the container has been removed. Could we close the streaming connection when the container is removed? |
👍 I use the cli version of this (docker logs -f ) in a dokku plugin and if there is nothing to be done by the plugin, by the time I execute this the container is stopped and thus the deployment will hang. I actually think it makes sense to support both semantics. Think tail -f vs. tail -F, sort of. 😄 |
@michaelshobbs if you always issue the call with the container stopped, you may omit The problem in tsuru is that we cannot guarantee that we call Logs before the container stops. |
That's the thing, its only the edge case where the container is stopped. Under normal circumstances, the container will be running. |
@fsouze @michaelshobbs Do you have guys any suggestions how it should be? Just not to begin follow if container is stopped? |
@LK4D4 I believe that would break A good approach would be to stop streaming when the container is removed, but I don't know if this would fix the @michaelshobbs case. This is how tsuru approach looks like today:
AttachToContainer is already broken for the case where the container is stopped, but it hangs inside a goroutine. If Logs cannot replace Attach + Wait call, we aren't able to use it. |
@LK4D4 Let me preface by saying my understanding of the underpinnings of docker are limited. I am primarily a CLI user and have not dug into what is happening at the API level or deeper. The way docker logs -f functioned before made the most sense to me. If the container is running, print the log from container start (?) and keep the stream open until the container completed. If the container is stopped, function the same as if -f was not passed. i.e. just print the log, close the stream and exit. |
@fsouza Really logs now not connected with any other calls, so it can't break anything. If someone for core team approve that we don't stream logs for stopped containers I can implement this. |
@LK4D4 My opinion is that we should make the behavior consistent, and autoexit |
If we were to introduce Would this breaking change be that annoying? |
@tiborvass I would actually expect the behavior to be the opposite as -f would be the normal case and quit if the container was stopped and -F would leave the stream open. My expectation of that normal case came from how logs -f worked prior to 1.0. I'm fine with adjusting that if you guys think the opposite makes more sense. |
@michaelshobbs oh thanks for clarifying. I looked at |
@tiborvass Backwards compatibility was my thinking, yes. |
I'm confused - how would that be the opposite of tail? With So TL;DR I'm +1 for a new |
@tianon That's not exactly true. A |
Ah true. +1 :) |
Regardless I think we should let Docker logs --follow exit when the container is completely removed. I'm more or so fine when it's just stopped but if the container is no longer present docker logs --follow shouldn't need to be intervened. |
Found a bug when you launch docker logs --follow after the container stops, pasting the repro steps from #7577 in bash #1 after in bash #2 looking back at the docker logs --follow process it's still hanging there forever. |
So, guys, let's decide what we do. |
👍 |
@LK4D4 I'm fine with that. |
Sounds good, as long the logs process will exit when the container is removed! (which it doesn't now) |
I don't know whether this is on purpose or not, but we have an issue when using the API for logs. We can't guarantee that the container is not running when we call the
/logs
endpoints withfollow=1
, so we may end-up waiting forever.Is this a bug or the expected behaviour? If the former, I can try to fix it, if the later, I will have to work around it.
The text was updated successfully, but these errors were encountered: