summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-02 12:36:04 -0400
committerGitHub <noreply@github.com>2020-07-02 12:36:04 -0400
commit22def2e2d98fd2ac4f6709bd094ee66bda9c648b (patch)
tree7e795ae88a3df174bb7d399a115c2178ec4fd93b /pkg/api/handlers
parentc131567401bea2867d597d79cce75b99012e64fb (diff)
parent9e4cf6ca513fa0646f33ade14955e1fc4335e176 (diff)
downloadpodman-22def2e2d98fd2ac4f6709bd094ee66bda9c648b.tar.gz
podman-22def2e2d98fd2ac4f6709bd094ee66bda9c648b.tar.bz2
podman-22def2e2d98fd2ac4f6709bd094ee66bda9c648b.zip
Merge pull request #6838 from mheon/fix_panic_events
Fix `system service` panic from early hangup in events
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/compat/events.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go
index 577ddd0a1..fca50c321 100644
--- a/pkg/api/handlers/compat/events.go
+++ b/pkg/api/handlers/compat/events.go
@@ -1,6 +1,7 @@
package compat
import (
+ "context"
"fmt"
"net/http"
@@ -45,13 +46,15 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
fromStart = true
}
+ eventCtx, eventCancel := context.WithCancel(r.Context())
eventChannel := make(chan *events.Event)
go func() {
readOpts := events.ReadOptions{FromStart: fromStart, Stream: query.Stream, Filters: libpodFilters, EventChannel: eventChannel, Since: query.Since, Until: query.Until}
- eventsError = runtime.Events(readOpts)
+ eventsError = runtime.Events(eventCtx, readOpts)
}()
if eventsError != nil {
utils.InternalServerError(w, eventsError)
+ eventCancel()
close(eventChannel)
return
}
@@ -59,6 +62,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
// If client disappears we need to stop listening for events
go func(done <-chan struct{}) {
<-done
+ eventCancel()
if _, ok := <-eventChannel; ok {
close(eventChannel)
}