diff options
author | Matthew Heon <matthew.heon@pm.me> | 2020-07-01 16:21:57 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-07-02 09:57:39 -0400 |
commit | 9e4cf6ca513fa0646f33ade14955e1fc4335e176 (patch) | |
tree | 9c820378fb4e2d0873ca24da5766691ffc4b6ccd /pkg/varlinkapi | |
parent | 1a1e3f4b24e6f856a5c2e16da0cc34a8191c9403 (diff) | |
download | podman-9e4cf6ca513fa0646f33ade14955e1fc4335e176.tar.gz podman-9e4cf6ca513fa0646f33ade14955e1fc4335e176.tar.bz2 podman-9e4cf6ca513fa0646f33ade14955e1fc4335e176.zip |
Fix `system service` panic from early hangup in events
We weren't actually halting the goroutine that sent events, so it
would continue sending even when the channel closed (the most
notable cause being early hangup - e.g. Control-c on a curl
session). Use a context to cancel the events goroutine and stop
sending events.
Fixes #6805
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'pkg/varlinkapi')
-rw-r--r-- | pkg/varlinkapi/attach.go | 3 | ||||
-rw-r--r-- | pkg/varlinkapi/events.go | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/pkg/varlinkapi/attach.go b/pkg/varlinkapi/attach.go index db977ee5c..2a54d63b5 100644 --- a/pkg/varlinkapi/attach.go +++ b/pkg/varlinkapi/attach.go @@ -4,6 +4,7 @@ package varlinkapi import ( "bufio" + "context" "io" "github.com/containers/libpod/libpod" @@ -89,7 +90,7 @@ func (i *VarlinkAPI) Attach(call iopodman.VarlinkCall, name string, detachKeys s if ecode, err := ctr.Wait(); err != nil { if errors.Cause(err) == define.ErrNoSuchCtr { // Check events - event, err := i.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited) + event, err := i.Runtime.GetLastContainerEvent(context.Background(), ctr.ID(), events.Exited) if err != nil { logrus.Errorf("Cannot get exit code: %v", err) exitCode = define.ExecErrorCodeNotFound diff --git a/pkg/varlinkapi/events.go b/pkg/varlinkapi/events.go index 33938f08b..471afb7a3 100644 --- a/pkg/varlinkapi/events.go +++ b/pkg/varlinkapi/events.go @@ -3,6 +3,7 @@ package varlinkapi import ( + "context" "time" "github.com/containers/libpod/libpod/events" @@ -27,7 +28,7 @@ func (i *VarlinkAPI) GetEvents(call iopodman.VarlinkCall, filter []string, since eventChannel := make(chan *events.Event) go func() { readOpts := events.ReadOptions{FromStart: fromStart, Stream: stream, Filters: filter, EventChannel: eventChannel} - eventsError = i.Runtime.Events(readOpts) + eventsError = i.Runtime.Events(context.Background(), readOpts) }() if eventsError != nil { return call.ReplyErrorOccurred(eventsError.Error()) |