Skip to content

Fix -f logs follow with stopped container#6559

Closed
QiWang19 wants to merge 1 commit into
containers:masterfrom
QiWang19:log-ctr-state
Closed

Fix -f logs follow with stopped container#6559
QiWang19 wants to merge 1 commit into
containers:masterfrom
QiWang19:log-ctr-state

Conversation

@QiWang19
Copy link
Copy Markdown
Member

@QiWang19 QiWang19 commented Jun 10, 2020

Fix -f logs follow with stopped container. Close #6531

Signed-off-by: Qi Wang qiwan@redhat.com

@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: QiWang19
To complete the pull request process, please assign baude
You can assign the PR to them by writing /assign @baude in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mheon
Copy link
Copy Markdown
Member

mheon commented Jun 10, 2020

Does this fix journald logging as well, or just file logging?

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 10, 2020

Does this work correct.

In one window run

podman run --name test -ti fedora bash -c "sleep 10; ls -R /"

In a separatee window

podman log test

When the first container ends, does the podman log command also end?

@QiWang19
Copy link
Copy Markdown
Member Author

This just unset the follow options for the file logging.

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 10, 2020

Right but it has no effect on a running log.

@QiWang19
Copy link
Copy Markdown
Member Author

Looks not right, If run logs -f test in a separate window, the log command directly ends without logging anything.

@jgallucci32
Copy link
Copy Markdown
Contributor

@QiWang19 When following logs on a running container, if the container is stopped, does the logging stop as well? I want to make sure this covers both use cases

  • When following logs on stopped container, exit immediately
  • When following logs on a running container, exit when container is stopped

@QiWang19
Copy link
Copy Markdown
Member Author

* When following logs on a running container, exit when container is stopped
* When following logs on stopped container, exit immediately

Yes, the current upstream has both these issues that should be fixed and I am working on.

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 11, 2020

@QiWang19 Could you rebase and repush. Tests do not seem to have run. Have you confirmed that this is running the way it should?

@QiWang19
Copy link
Copy Markdown
Member Author

This PR not fully fixed the issue. Still need more work on this.

Fix -f logs follow with stopped container. Close containers#6531

Signed-off-by: Qi Wang <qiwan@redhat.com>
@QiWang19 QiWang19 changed the title Fix skip logs follow with stopped container Fix -f logs follow with stopped container Jun 11, 2020
@jgallucci32
Copy link
Copy Markdown
Contributor

jgallucci32 commented Jun 12, 2020

@QiWang19 I just tested this and following the logs hangs indefinitely if the container is running before running logs -f container and after it stops. It will no longer hang if the container is already stopped, but stopping a container while tailing the logs continues to be an issue.

@jgallucci32
Copy link
Copy Markdown
Contributor

@QiWang19 I have traced the hang in the code to this line
https://github.com/containers/libpod/blob/033743cbee180d9a4149f574375cc1201e573d06/libpod/container_log.go#L61
Since the Lines() function is external to libpod we're likely going to have to loop and check for it like the original fix was written 2 years ago (it had a time.Sleep(1 * time.Second) line within a loop to check the state of the container every second)

@jgallucci32
Copy link
Copy Markdown
Contributor

jgallucci32 commented Jun 12, 2020

@QiWang19 I created a PR against your branch which handles multiple scenarios of following a log with stopped (or stopping) containers.
QiWang19#1

What this does is create a subroutine which checks the state of the container every second. This is a similar approach taken when this bug was fixed 2 years ago. The difference with the new code from 2 years ago is libpod is using github.com/hpcloud/tail which effectively follows a log until it is given an exit command. Before the logic for tailing a file was written as functions within libpod. hpcloud/tail has several options Kill, Stop, StopAtEOF so I chose what I thought would allow the function to exit most gracefully which is StopAtEOF().

I tested the following conditions with this PR:

  • Tail and follow logs of running container
  • Tail and follow logs of stopped container
  • Tail and follow logs of running container which exits after some time

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 12, 2020

@jgallucci32 Could you open a PR for libpod with Yours and @QiWang19 Changes combined and here tests, Leave her signature and then we can merge the combination.

@jgallucci32
Copy link
Copy Markdown
Contributor

@rhatdan I created PR #6591 which is a merge of our two commits. It will supercede this PR.

Not sure how to leave her signature, but there are 2 commits in the PR one from each of us.

@rhatdan rhatdan closed this Jun 12, 2020
@QiWang19 QiWang19 deleted the log-ctr-state branch June 26, 2020 15:10
@github-actions github-actions Bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman logs -f continues indefinitely on a stopped container

5 participants