summaryrefslogtreecommitdiff
path: root/libpod/container_log.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-06-21 14:31:26 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-06-22 13:18:04 +0200
commite5c070baff75d6f0d33a8088acb253d3790fb30a (patch)
treea1181fba79ececdf0f7a49349eb942b2d530a7e8 /libpod/container_log.go
parent4d9a9149dd127cff417766512ab902e0a7e009a7 (diff)
downloadpodman-e5c070baff75d6f0d33a8088acb253d3790fb30a.tar.gz
podman-e5c070baff75d6f0d33a8088acb253d3790fb30a.tar.bz2
podman-e5c070baff75d6f0d33a8088acb253d3790fb30a.zip
logs: k8s-file: restore poll sleep
Commit 84b55eec2796 attempted to fix a race waiting for the container died event. Previously, Podman slept for duration of the polling frequence which I considerred to be a mistake. As it turns out, I was mistaken since the file logger will, in fact, NOT read until EOF and then stop logging but stop logging immediately _after_ it woke up. [NO TESTS NEEDED] as the race condition cannot be hit reliably. Fixes: #10675 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/container_log.go')
-rw-r--r--libpod/container_log.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go
index 8bbb7ebe8..43b3f7736 100644
--- a/libpod/container_log.go
+++ b/libpod/container_log.go
@@ -4,10 +4,12 @@ import (
"context"
"fmt"
"os"
+ "time"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/libpod/logs"
+ "github.com/hpcloud/tail/watch"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -93,11 +95,14 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
}()
// Check if container is still running or paused
if options.Follow {
+ // If the container isn't running or if we encountered an error
+ // getting its state, instruct the logger to read the file
+ // until EOF.
state, err := c.State()
if err != nil || state != define.ContainerStateRunning {
- // If the container isn't running or if we encountered
- // an error getting its state, instruct the logger to
- // read the file until EOF.
+ // 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)
@@ -124,6 +129,9 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
// Now wait for the died event and signal to finish
// reading the log until EOF.
<-eventChannel
+ // 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)