From 77db7ad61889c76ffeac463b66cfb633970d2603 Mon Sep 17 00:00:00 2001 From: Aaron Knister Date: Sun, 17 Apr 2016 20:03:17 -0400 Subject: [PATCH] Prevent goroutine leak in http service for persistent query connections --- CHANGELOG.md | 1 + services/httpd/handler.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae28217e3b6..743510a4835 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 e61f55c6f12..8df25f5f1d5 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)