diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-07-09 13:32:20 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-07-09 15:13:07 +0200 |
commit | 09dc77aedfb786505bc526536be18d457fb7c68b (patch) | |
tree | d45bf64bf131493553f3444880a1386d9b238f04 /libpod/container_log_linux.go | |
parent | edf5fe8b17f39ce98805c279b9795bfd4123abe2 (diff) | |
download | podman-09dc77aedfb786505bc526536be18d457fb7c68b.tar.gz podman-09dc77aedfb786505bc526536be18d457fb7c68b.tar.bz2 podman-09dc77aedfb786505bc526536be18d457fb7c68b.zip |
log API: add context to allow for cancelling
Add a `context.Context` to the log APIs to allow for cancelling
streaming (e.g., via `podman logs -f`). This fixes issues for
the remote API where some go routines of the server will continue
writing and produce nothing but heat and waste CPU cycles.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/container_log_linux.go')
-rw-r--r-- | libpod/container_log_linux.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go index fad3bf87c..00b2039a9 100644 --- a/libpod/container_log_linux.go +++ b/libpod/container_log_linux.go @@ -4,6 +4,7 @@ package libpod import ( + "context" "fmt" "io" "math" @@ -29,7 +30,7 @@ const ( bufLen = 16384 ) -func (c *Container) readFromJournal(options *logs.LogOptions, logChannel chan *logs.LogLine) error { +func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error { var config journal.JournalReaderConfig if options.Tail < 0 { config.NumFromTail = math.MaxUint64 @@ -65,13 +66,24 @@ func (c *Container) readFromJournal(options *logs.LogOptions, logChannel chan *l if options.Follow { go func() { + done := make(chan bool) + until := make(chan time.Time) + go func() { + select { + case <-ctx.Done(): + until <- time.Time{} + case <-done: + // nothing to do anymore + } + }() follower := FollowBuffer{logChannel} - err := r.Follow(nil, follower) + err := r.Follow(until, follower) if err != nil { logrus.Debugf(err.Error()) } r.Close() options.WaitGroup.Done() + done <- true return }() return nil |