From 494024fe26dde392813c475ad791e9454878864e Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Feb 2022 02:10:48 +0100 Subject: [PATCH] Add IdleConnTimeout configurable for http transport --- config/config.go | 1 + config/default.go | 1 + config/load.go | 1 + main.go | 1 + 4 files changed, 4 insertions(+) diff --git a/config/config.go b/config/config.go index 85edd5fdb..35ab42611 100644 --- a/config/config.go +++ b/config/config.go @@ -66,6 +66,7 @@ type Proxy struct { DialTimeout time.Duration ResponseHeaderTimeout time.Duration KeepAliveTimeout time.Duration + IdleConnTimeout time.Duration FlushInterval time.Duration GlobalFlushInterval time.Duration LocalIP string diff --git a/config/default.go b/config/default.go index 5738b0392..b26758551 100644 --- a/config/default.go +++ b/config/default.go @@ -47,6 +47,7 @@ var defaultConfig = &Config{ GlobalFlushInterval: 0, LocalIP: LocalIPString(), AuthSchemes: map[string]AuthScheme{}, + IdleConnTimeout: 15 * time.Second, }, Registry: Registry{ Backend: "consul", diff --git a/config/load.go b/config/load.go index 60ce836b1..47bbd51c3 100644 --- a/config/load.go +++ b/config/load.go @@ -129,6 +129,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c f.DurationVar(&cfg.Proxy.DialTimeout, "proxy.dialtimeout", defaultConfig.Proxy.DialTimeout, "connection timeout for backend connections") f.DurationVar(&cfg.Proxy.ResponseHeaderTimeout, "proxy.responseheadertimeout", defaultConfig.Proxy.ResponseHeaderTimeout, "response header timeout") f.DurationVar(&cfg.Proxy.KeepAliveTimeout, "proxy.keepalivetimeout", defaultConfig.Proxy.KeepAliveTimeout, "keep-alive timeout") + f.DurationVar(&cfg.Proxy.IdleConnTimeout, "proxy.idleconntimeout", defaultConfig.Proxy.IdleConnTimeout, "idle timeout, when to close (keep-alive) connections") f.StringVar(&cfg.Proxy.LocalIP, "proxy.localip", defaultConfig.Proxy.LocalIP, "fabio address in Forward headers") f.StringVar(&cfg.Proxy.ClientIPHeader, "proxy.header.clientip", defaultConfig.Proxy.ClientIPHeader, "header for the request ip") f.StringVar(&cfg.Proxy.TLSHeader, "proxy.header.tls", defaultConfig.Proxy.TLSHeader, "header for TLS connections") diff --git a/main.go b/main.go index 617673550..e17e1f169 100644 --- a/main.go +++ b/main.go @@ -213,6 +213,7 @@ func newHTTPProxy(cfg *config.Config) http.Handler { newTransport := func(tlscfg *tls.Config) *http.Transport { return &http.Transport{ ResponseHeaderTimeout: cfg.Proxy.ResponseHeaderTimeout, + IdleConnTimeout: cfg.Proxy.IdleConnTimeout, MaxIdleConnsPerHost: cfg.Proxy.MaxConn, Dial: (&net.Dialer{ Timeout: cfg.Proxy.DialTimeout,