diff --git a/CHANGELOG.md b/CHANGELOG.md index ae28217e3b..743510a483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#6383](https://github.com/influxdata/influxdb/pull/6383): Recover from a panic during query execution. - [#3369](https://github.com/influxdata/influxdb/issues/3369): Detect when a timer literal will overflow or underflow the query engine. - [#6398](https://github.com/influxdata/influxdb/issues/6398): Fix CREATE RETENTION POLICY parsing so it doesn't consume tokens it shouldn't. +- [#6413](https://github.com/influxdata/influxdb/pull/6413): Prevent goroutine leak from persistent http connections. Thanks @aaronknister. ## v0.12.1 [2016-04-08] diff --git a/services/httpd/handler.go b/services/httpd/handler.go index e61f55c6f1..8df25f5f1d 100644 --- a/services/httpd/handler.go +++ b/services/httpd/handler.go @@ -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)