mirror of
https://github.com/containers/podman.git
synced 2025-06-26 12:56:45 +08:00
Merge pull request #11464 from vrothberg/fix-11461
logs -f: file: fix dead lock
This commit is contained in:
@ -107,16 +107,18 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
|
|||||||
// until EOF.
|
// until EOF.
|
||||||
state, err := c.State()
|
state, err := c.State()
|
||||||
if err != nil || state != define.ContainerStateRunning {
|
if err != nil || state != define.ContainerStateRunning {
|
||||||
// Make sure to wait at least for the poll duration
|
|
||||||
// before stopping the file logger (see #10675).
|
|
||||||
time.Sleep(watch.POLL_DURATION)
|
|
||||||
tailError := t.StopAtEOF()
|
|
||||||
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
|
|
||||||
logrus.Errorf("Error stopping logger: %v", tailError)
|
|
||||||
}
|
|
||||||
if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
|
if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
|
||||||
logrus.Errorf("Error getting container state: %v", err)
|
logrus.Errorf("Error getting container state: %v", err)
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
// Make sure to wait at least for the poll duration
|
||||||
|
// before stopping the file logger (see #10675).
|
||||||
|
time.Sleep(watch.POLL_DURATION)
|
||||||
|
tailError := t.StopAtEOF()
|
||||||
|
if tailError != nil && tailError.Error() != "tail: stop at eof" {
|
||||||
|
logrus.Errorf("Error stopping logger: %v", tailError)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,4 +174,31 @@ $s_after"
|
|||||||
_log_test_until journald
|
_log_test_until journald
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _log_test_follow() {
|
||||||
|
local driver=$1
|
||||||
|
cname=$(random_string)
|
||||||
|
contentA=$(random_string)
|
||||||
|
contentB=$(random_string)
|
||||||
|
contentC=$(random_string)
|
||||||
|
|
||||||
|
# Note: it seems we need at least three log lines to hit #11461.
|
||||||
|
run_podman run --log-driver=$driver --name $cname $IMAGE sh -c "echo $contentA; echo $contentB; echo $contentC"
|
||||||
|
run_podman logs -f $cname
|
||||||
|
is "$output" "$contentA
|
||||||
|
$contentB
|
||||||
|
$contentC" "logs -f on exitted container works"
|
||||||
|
|
||||||
|
run_podman rm -f $cname
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "podman logs - --follow k8s-file" {
|
||||||
|
_log_test_follow k8s-file
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "podman logs - --follow journald" {
|
||||||
|
# We can't use journald on RHEL as rootless: rhbz#1895105
|
||||||
|
skip_if_journald_unavailable
|
||||||
|
|
||||||
|
_log_test_follow journald
|
||||||
|
}
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user