@marcel91200 / caddy Mirror · read-only / commits / 7c68809f
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverseproxy: Fix overwriting of max_idle_conns_per_host (closes #4201)

Also split the Caddyfile subdirective keepalive_idle_conns into two properties so the conns and conns_per_host can be set separately. This is technically a breaking change, but probably anyone who this breaks already had a broken config anyway, and silently fixing it won't help them fix their configs.

Matthew Holt committed Jun 15, 2021 at 14:54 UTC 7c68809f4e13a7ac7c9e216a69410e7c1966c1df
3 files changed +16 -18
modules/caddyhttp/reverseproxy/caddyfile.go
+12 -10
@@ -978,6 +978,18 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
978 h.KeepAlive = new(KeepAlive)
979 }
980 h.KeepAlive.MaxIdleConns = num
981 +
982 + case "keepalive_idle_conns_per_host":
983 + if !d.NextArg() {
984 + return d.ArgErr()
985 + }
986 + num, err := strconv.Atoi(d.Val())
987 + if err != nil {
988 + return d.Errf("bad integer value '%s': %v", d.Val(), err)
989 + }
990 + if h.KeepAlive == nil {
991 + h.KeepAlive = new(KeepAlive)
992 + }
993 h.KeepAlive.MaxIdleConnsPerHost = num
994
995 case "versions":
@@ -1004,16 +1016,6 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
1016 }
1017 h.MaxConnsPerHost = num
1018
1007 - case "max_idle_conns_per_host":
1008 - if !d.NextArg() {
1009 - return d.ArgErr()
1010 - }
1011 - num, err := strconv.Atoi(d.Val())
1012 - if err != nil {
1013 - return d.Errf("bad integer value '%s': %v", d.Val(), err)
1014 - }
1015 - h.MaxIdleConnsPerHost = num
1016 -
1019 default:
1020 return d.Errf("unrecognized subdirective %s", d.Val())
1021 }
modules/caddyhttp/reverseproxy/httptransport.go
+3 -7
@@ -62,9 +62,6 @@ type HTTPTransport struct {
62 // Maximum number of connections per host. Default: 0 (no limit)
63 MaxConnsPerHost int `json:"max_conns_per_host,omitempty"`
64
65 - // Maximum number of idle connections per host. Default: 0 (uses Go's default of 2)
66 - MaxIdleConnsPerHost int `json:"max_idle_conns_per_host,omitempty"`
67 -
65 // How long to wait before timing out trying to connect to
66 // an upstream.
67 DialTimeout caddy.Duration `json:"dial_timeout,omitempty"`
@@ -197,7 +194,6 @@ func (h *HTTPTransport) NewTransport(ctx caddy.Context) (*http.Transport, error)
194 return conn, nil
195 },
196 MaxConnsPerHost: h.MaxConnsPerHost,
200 - MaxIdleConnsPerHost: h.MaxIdleConnsPerHost,
197 ResponseHeaderTimeout: time.Duration(h.ResponseHeaderTimeout),
198 ExpectContinueTimeout: time.Duration(h.ExpectContinueTimeout),
199 MaxResponseHeaderBytes: h.MaxResponseHeaderSize,
@@ -412,13 +408,13 @@ type KeepAlive struct {
408 // How often to probe for liveness.
409 ProbeInterval caddy.Duration `json:"probe_interval,omitempty"`
410
415 - // Maximum number of idle connections.
411 + // Maximum number of idle connections. Default: 0, which means no limit.
412 MaxIdleConns int `json:"max_idle_conns,omitempty"`
413
418 - // Maximum number of idle connections per upstream host.
414 + // Maximum number of idle connections per host. Default: 0, which uses Go's default of 2.
415 MaxIdleConnsPerHost int `json:"max_idle_conns_per_host,omitempty"`
416
421 - // How long connections should be kept alive when idle.
417 + // How long connections should be kept alive when idle. Default: 0, which means no timeout.
418 IdleConnTimeout caddy.Duration `json:"idle_timeout,omitempty"`
419 }
420
modules/caddyhttp/reverseproxy/reverseproxy.go
+1 -1
@@ -204,7 +204,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
204 KeepAlive: &KeepAlive{
205 ProbeInterval: caddy.Duration(30 * time.Second),
206 IdleConnTimeout: caddy.Duration(2 * time.Minute),
207 - MaxIdleConnsPerHost: 32,
207 + MaxIdleConnsPerHost: 32, // seems about optimal, see #2805
208 },
209 DialTimeout: caddy.Duration(10 * time.Second),
210 }