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-20 11:37:05 +0200
commitd856e87f4002fa520594a2c843cb7e3b002cbb6e (patch)
tree033c6a34201bbefe2f503f4a6c1f497005c3c916 /libpod/events
parentb7b8fce82693ae0f9ebb0561cd3e6c118ad35fe9 (diff)
downloadpodman-d856e87f4002fa520594a2c843cb7e3b002cbb6e.tar.gz
podman-d856e87f4002fa520594a2c843cb7e3b002cbb6e.tar.bz2
podman-d856e87f4002fa520594a2c843cb7e3b002cbb6e.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