diff --git a/web/server.go b/web/server.go index 2eef970..358fdcf 100644 --- a/web/server.go +++ b/web/server.go @@ -442,20 +442,22 @@ func (s *Server) handleEvents() http.HandlerFunc { }() // Keep connection open and send events as they arrive - for { - select { - case msg, ok := <-clientChan: - if !ok { + go func() { + for { + select { + case msg, ok := <-clientChan: + if !ok { + return + } + fmt.Fprintf(w, "%s\n\n", msg) + if flusher, ok := w.(http.Flusher); ok { + flusher.Flush() + } + case <-r.Context().Done(): return } - fmt.Fprintf(w, "%s\n\n", msg) - if flusher, ok := w.(http.Flusher); ok { - flusher.Flush() - } - case <-r.Context().Done(): - return } - } + }() } } @@ -503,20 +505,22 @@ func (s *Server) handleAdminEvents() http.HandlerFunc { }() // Keep connection open and send events as they arrive - for { - select { - case msg, ok := <-clientChan: - if !ok { + go func() { + for { + select { + case msg, ok := <-clientChan: + if !ok { + return + } + fmt.Fprintf(w, "%s\n\n", msg) + if flusher, ok := w.(http.Flusher); ok { + flusher.Flush() + } + case <-r.Context().Done(): return } - fmt.Fprintf(w, "%s\n\n", msg) - if flusher, ok := w.(http.Flusher); ok { - flusher.Flush() - } - case <-r.Context().Done(): - return } - } + }() } }