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 /libpod/events.go | |
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 'libpod/events.go')
-rw-r--r-- | libpod/events.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/libpod/events.go b/libpod/events.go index 3d07c5d76..b587f1697 100644 --- a/libpod/events.go +++ b/libpod/events.go @@ -1,6 +1,7 @@ package libpod import ( + "context" "fmt" "github.com/containers/libpod/libpod/events" @@ -75,16 +76,16 @@ func (v *Volume) newVolumeEvent(status events.Status) { // Events is a wrapper function for everyone to begin tailing the events log // with options -func (r *Runtime) Events(options events.ReadOptions) error { +func (r *Runtime) Events(ctx context.Context, options events.ReadOptions) error { eventer, err := r.newEventer() if err != nil { return err } - return eventer.Read(options) + return eventer.Read(ctx, options) } // GetEvents reads the event log and returns events based on input filters -func (r *Runtime) GetEvents(filters []string) ([]*events.Event, error) { +func (r *Runtime) GetEvents(ctx context.Context, filters []string) ([]*events.Event, error) { var readErr error eventChannel := make(chan *events.Event) options := events.ReadOptions{ @@ -98,7 +99,7 @@ func (r *Runtime) GetEvents(filters []string) ([]*events.Event, error) { return nil, err } go func() { - readErr = eventer.Read(options) + readErr = eventer.Read(ctx, options) }() if readErr != nil { return nil, readErr @@ -112,7 +113,7 @@ func (r *Runtime) GetEvents(filters []string) ([]*events.Event, error) { // GetLastContainerEvent takes a container name or ID and an event status and returns // the last occurrence of the container event -func (r *Runtime) GetLastContainerEvent(nameOrID string, containerEvent events.Status) (*events.Event, error) { +func (r *Runtime) GetLastContainerEvent(ctx context.Context, nameOrID string, containerEvent events.Status) (*events.Event, error) { // check to make sure the event.Status is valid if _, err := events.StringToStatus(containerEvent.String()); err != nil { return nil, err @@ -122,7 +123,7 @@ func (r *Runtime) GetLastContainerEvent(nameOrID string, containerEvent events.S fmt.Sprintf("event=%s", containerEvent), "type=container", } - containerEvents, err := r.GetEvents(filters) + containerEvents, err := r.GetEvents(ctx, filters) if err != nil { return nil, err } |