From 21db76b3374c733f37ed16ad93f3484020034351 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 19 Apr 2016 12:05:43 -0600 Subject: [PATCH] Prevent InfluxDB client from leaking TCP connections If users properly call client.Close(), then this will make sure that established tcp connections dont continually grow when creating new http clients. This fixes the case where users are creating new http clients on top of existing _valid_ connections. This was encountered in Telegraf when we were recreating our http clients after getting write failures that were unrelated to the actual connection being severed (such as typos in the retention policy, see https://github.com/influxdata/telegraf/issues/1058) --- CHANGELOG.md | 1 + client/v2/client.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67456fee0b..be9c11f406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - [#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. - [#6414](https://github.com/influxdata/influxdb/pull/6414): Send "Connection: close" header for queries. +- [#6425](https://github.com/influxdata/influxdb/pull/6425): Close idle tcp connections in HTTP client to prevent tcp conn leak. ## v0.12.1 [2016-04-08] diff --git a/client/v2/client.go b/client/v2/client.go index 32ef1afc4f..3776eab304 100644 --- a/client/v2/client.go +++ b/client/v2/client.go @@ -123,6 +123,7 @@ func NewHTTPClient(conf HTTPConfig) (Client, error) { Timeout: conf.Timeout, Transport: tr, }, + transport: tr, }, nil } @@ -172,6 +173,7 @@ func (c *client) Ping(timeout time.Duration) (time.Duration, string, error) { // Close releases the client's resources. func (c *client) Close() error { + c.transport.CloseIdleConnections() return nil } @@ -221,6 +223,7 @@ type client struct { password string useragent string httpClient *http.Client + transport *http.Transport } type udpclient struct {