From a8cce41882e5d94f876d93c1b7c29d37a32f58eb Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 17 Dec 2017 15:15:04 +0000 Subject: [PATCH] Set MaxIdleConnsPerHost alongside MaxIdleConns (#3592) Otherwise it defaults to 2, and Go will close extra connections as soon as a request is finished. See https://github.com/golang/go/issues/13801 --- util/httputil/client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/httputil/client.go b/util/httputil/client.go index e36e35361..99469c37b 100644 --- a/util/httputil/client.go +++ b/util/httputil/client.go @@ -41,11 +41,12 @@ func NewClientFromConfig(cfg config.HTTPClientConfig, name string) (*http.Client // The only timeout we care about is the configured scrape timeout. // It is applied on request. So we leave out any timings here. var rt http.RoundTripper = &http.Transport{ - Proxy: http.ProxyURL(cfg.ProxyURL.URL), - MaxIdleConns: 20000, - DisableKeepAlives: false, - TLSClientConfig: tlsConfig, - DisableCompression: true, + Proxy: http.ProxyURL(cfg.ProxyURL.URL), + MaxIdleConns: 20000, + MaxIdleConnsPerHost: 1000, // see https://github.com/golang/go/issues/13801 + DisableKeepAlives: false, + TLSClientConfig: tlsConfig, + DisableCompression: true, // 5 minutes is typically above the maximum sane scrape interval. So we can // use keepalive for all configurations. IdleConnTimeout: 5 * time.Minute,