Skip to content

Commit

Permalink
Prevent goroutine leak in http service for persistent query connections
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronknister committed Apr 18, 2016
1 parent 7a12747 commit 65e1b73
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,16 @@ func (h *Handler) serveQuery(w http.ResponseWriter, r *http.Request, user *meta.
closing := make(chan struct{})
if notifier, ok := w.(http.CloseNotifier); ok {
notify := notifier.CloseNotify()
done := make(chan struct{})
defer close(done)
go func() {
<-notify
close(closing)
// Wait for either the request to finish
// or for the client to disconnect
select {
case <-done:
case <-notify:
close(closing)
}
}()
} else {
defer close(closing)
Expand Down

0 comments on commit 65e1b73

Please sign in to comment.