summaryrefslogtreecommitdiff
path: root/libpod/events
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-07-08 13:50:52 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-07-21 16:56:26 +0200
commit142db01942e67b11f7daf2cc82e21409233aff0b (patch)
treed486bff84a2a07f3d0edff3bf3cc5b1501aa63ab /libpod/events
parent1b8d0e454353224a571bcec7d37240140ec7917f (diff)
downloadpodman-142db01942e67b11f7daf2cc82e21409233aff0b.tar.gz
podman-142db01942e67b11f7daf2cc82e21409233aff0b.tar.bz2
podman-142db01942e67b11f7daf2cc82e21409233aff0b.zip
events endpoint: fix panic and race condition
Fix a potential panic in the events endpoint when parsing the filters parameter. Values of the filters map might be empty, so we need to account for that instead of uncondtitionally accessing the first item. Also apply a similar for race conditions as done in commit f4a2d25c0fca: Fix a race that could cause read errors to be masked. Masking such errors is likely to report red herrings since users don't see that reading failed for some reasons but that a given event could not be found. Another race was the handler closing event channel, which could lead to two kinds of panics: double close, send to close channel. The backend takes care of that. However, make sure that the backend stops working in case the context has been cancelled. Fixes: #6899 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/events')
-rw-r--r--libpod/events/journal_linux.go7
-rw-r--r--libpod/events/logfile.go8
2 files changed, 15 insertions, 0 deletions
diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go
index d341ca7b5..7c2a3e0f2 100644
--- a/libpod/events/journal_linux.go
+++ b/libpod/events/journal_linux.go
@@ -90,6 +90,13 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
return err
}
for {
+ select {
+ case <-ctx.Done():
+ // the consumer has cancelled
+ return nil
+ default:
+ // fallthrough
+ }
if _, err := j.Next(); err != nil {
return err
}
diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go
index 28d0dc07e..b70102450 100644
--- a/libpod/events/logfile.go
+++ b/libpod/events/logfile.go
@@ -63,6 +63,14 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
}
}()
for line := range t.Lines {
+ select {
+ case <-ctx.Done():
+ // the consumer has cancelled
+ return nil
+ default:
+ // fallthrough
+ }
+
event, err := newEventFromJSONString(line.Text)
if err != nil {
return err