diff options
Diffstat (limited to 'pkg/api/handlers/compat/events.go')
-rw-r--r-- | pkg/api/handlers/compat/events.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go index 577ddd0a1..5acc94153 100644 --- a/pkg/api/handlers/compat/events.go +++ b/pkg/api/handlers/compat/events.go @@ -1,13 +1,14 @@ package compat import ( + "context" "fmt" "net/http" - "github.com/containers/libpod/libpod" - "github.com/containers/libpod/libpod/events" - "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/containers/libpod/pkg/domain/entities" + "github.com/containers/libpod/v2/libpod" + "github.com/containers/libpod/v2/libpod/events" + "github.com/containers/libpod/v2/pkg/api/handlers/utils" + "github.com/containers/libpod/v2/pkg/domain/entities" "github.com/gorilla/schema" jsoniter "github.com/json-iterator/go" "github.com/pkg/errors" @@ -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) } |