Skip to content

Commit 3792bde

Browse files
committed
feat(config): configure HTTP transport pool
1 parent bb051a7 commit 3792bde

9 files changed

Lines changed: 136 additions & 5 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ PROXY_MAX_CONNECTIONS=1024
2121
PROXY_MAX_CONNECTIONS_PER_IP=64
2222
PROXY_MAX_TUNNELS=256
2323
PROXY_MAX_TUNNELS_PER_IP=16
24+
PROXY_MAX_IDLE_CONNS=100
25+
PROXY_MAX_IDLE_CONNS_PER_HOST=10
2426
PROXY_MAX_HEADER_BYTES=65536
2527
PROXY_TUNNEL_IDLE_TIMEOUT=10m
2628

@@ -39,6 +41,7 @@ PROXY_ALLOW_PRIVATE_DESTINATIONS=false
3941
# PROXY_TLS_HANDSHAKE_TIMEOUT=10s
4042
# PROXY_TLS_RELOAD_INTERVAL=1m
4143
# PROXY_RESPONSE_HEADER_TIMEOUT=30s
44+
# PROXY_IDLE_CONN_TIMEOUT=90s
4245
# PROXY_READ_HEADER_TIMEOUT=15s
4346
# PROXY_IDLE_TIMEOUT=2m
4447
# PROXY_SHUTDOWN_TIMEOUT=15s

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Any of these override the corresponding YAML field:
7878
| `PROXY_MAX_CONNECTIONS_PER_IP` | `max_connections_per_ip` |
7979
| `PROXY_MAX_TUNNELS` | `max_tunnels` |
8080
| `PROXY_MAX_TUNNELS_PER_IP` | `max_tunnels_per_ip` |
81+
| `PROXY_MAX_IDLE_CONNS` | `max_idle_conns` |
82+
| `PROXY_MAX_IDLE_CONNS_PER_HOST` | `max_idle_conns_per_host` |
8183
| `PROXY_MAX_HEADER_BYTES` | `max_header_bytes` |
8284
| `PROXY_AUTH_MAX_FAILURES` | `auth_max_failures` |
8385
| `PROXY_ALLOW_PRIVATE_DESTINATIONS` | `allow_private_destinations` |
@@ -86,6 +88,7 @@ Any of these override the corresponding YAML field:
8688
| `PROXY_TLS_HANDSHAKE_TIMEOUT` | `tls_handshake_timeout` |
8789
| `PROXY_TLS_RELOAD_INTERVAL` | `tls_reload_interval` |
8890
| `PROXY_RESPONSE_HEADER_TIMEOUT` | `response_header_timeout` |
91+
| `PROXY_IDLE_CONN_TIMEOUT` | `idle_conn_timeout` |
8992
| `PROXY_READ_HEADER_TIMEOUT` | `read_header_timeout` |
9093
| `PROXY_IDLE_TIMEOUT` | `idle_timeout` |
9194
| `PROXY_TUNNEL_IDLE_TIMEOUT` | `tunnel_idle_timeout` |
@@ -160,6 +163,8 @@ max_connections: 1024
160163
max_connections_per_ip: 128
161164
max_tunnels: 256
162165
max_tunnels_per_ip: 128
166+
max_idle_conns: 100
167+
max_idle_conns_per_host: 10
163168
max_header_bytes: 65536
164169
auth_max_failures: 10
165170
allow_private_destinations: false
@@ -168,6 +173,7 @@ dial_timeout: 10s
168173
tls_handshake_timeout: 10s
169174
tls_reload_interval: 1m
170175
response_header_timeout: 30s
176+
idle_conn_timeout: 90s
171177
read_header_timeout: 15s
172178
idle_timeout: 2m
173179
tunnel_idle_timeout: 10m
@@ -195,6 +201,8 @@ The example listens on localhost. Set `proxy_addr` to `0.0.0.0:8080` only when t
195201
| `max_connections_per_ip` | Maximum simultaneous client connections per source IP |
196202
| `max_tunnels` | Maximum simultaneous CONNECT tunnels |
197203
| `max_tunnels_per_ip` | Maximum simultaneous CONNECT tunnels per source IP |
204+
| `max_idle_conns` | Maximum idle outbound HTTP connections across all destinations |
205+
| `max_idle_conns_per_host` | Maximum idle outbound HTTP connections retained per destination |
198206
| `max_header_bytes` | Maximum size of incoming HTTP request headers |
199207
| `auth_max_failures` | Failed authentication attempts per IP before temporary blocking |
200208
| `allow_private_destinations` | Allow loopback, private, link-local, and other non-public destinations |
@@ -203,6 +211,7 @@ The example listens on localhost. Set `proxy_addr` to `0.0.0.0:8080` only when t
203211
| `tls_handshake_timeout` | Outbound TLS handshake timeout |
204212
| `tls_reload_interval` | How often new TLS handshakes check certificate files for a valid replacement |
205213
| `response_header_timeout` | Upstream CONNECT/HTTP response-header timeout |
214+
| `idle_conn_timeout` | How long an idle outbound HTTP connection remains pooled |
206215
| `read_header_timeout` | Incoming request-header timeout |
207216
| `idle_timeout` | Incoming keep-alive idle timeout |
208217
| `tunnel_idle_timeout` | Close a CONNECT tunnel after no traffic in either direction |

config.docker.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ max_connections: 1024
1010
max_connections_per_ip: 128
1111
max_tunnels: 256
1212
max_tunnels_per_ip: 128
13+
max_idle_conns: 100
14+
max_idle_conns_per_host: 10
1315
max_header_bytes: 65536
1416
auth_max_failures: 10
1517
allow_private_destinations: false
@@ -18,6 +20,7 @@ dial_timeout: 10s
1820
tls_handshake_timeout: 10s
1921
tls_reload_interval: 1m
2022
response_header_timeout: 30s
23+
idle_conn_timeout: 90s
2124
read_header_timeout: 15s
2225
idle_timeout: 2m
2326
tunnel_idle_timeout: 10m

config.example.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ max_connections: 1024
1010
max_connections_per_ip: 128
1111
max_tunnels: 256
1212
max_tunnels_per_ip: 128
13+
max_idle_conns: 100
14+
max_idle_conns_per_host: 10
1315
max_header_bytes: 65536
1416
auth_max_failures: 10
1517
allow_private_destinations: false
@@ -18,6 +20,7 @@ dial_timeout: 10s
1820
tls_handshake_timeout: 10s
1921
tls_reload_interval: 1m
2022
response_header_timeout: 30s
23+
idle_conn_timeout: 90s
2124
read_header_timeout: 15s
2225
idle_timeout: 2m
2326
tunnel_idle_timeout: 10m

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ services:
1818
PROXY_MAX_CONNECTIONS_PER_IP: "${PROXY_MAX_CONNECTIONS_PER_IP:-64}"
1919
PROXY_MAX_TUNNELS: "${PROXY_MAX_TUNNELS:-256}"
2020
PROXY_MAX_TUNNELS_PER_IP: "${PROXY_MAX_TUNNELS_PER_IP:-16}"
21+
PROXY_MAX_IDLE_CONNS: "${PROXY_MAX_IDLE_CONNS:-100}"
22+
PROXY_MAX_IDLE_CONNS_PER_HOST: "${PROXY_MAX_IDLE_CONNS_PER_HOST:-10}"
2123
PROXY_MAX_HEADER_BYTES: "${PROXY_MAX_HEADER_BYTES:-65536}"
24+
PROXY_IDLE_CONN_TIMEOUT: "${PROXY_IDLE_CONN_TIMEOUT:-90s}"
2225
PROXY_TUNNEL_IDLE_TIMEOUT: "${PROXY_TUNNEL_IDLE_TIMEOUT:-10m}"
2326
PROXY_AUTH_MAX_FAILURES: "${PROXY_AUTH_MAX_FAILURES:-10}"
2427
PROXY_AUTH_FAILURE_WINDOW: "${PROXY_AUTH_FAILURE_WINDOW:-1m}"
@@ -47,7 +50,10 @@ services:
4750
PROXY_MAX_CONNECTIONS_PER_IP: "${PROXY_MAX_CONNECTIONS_PER_IP:-64}"
4851
PROXY_MAX_TUNNELS: "${PROXY_MAX_TUNNELS:-256}"
4952
PROXY_MAX_TUNNELS_PER_IP: "${PROXY_MAX_TUNNELS_PER_IP:-16}"
53+
PROXY_MAX_IDLE_CONNS: "${PROXY_MAX_IDLE_CONNS:-100}"
54+
PROXY_MAX_IDLE_CONNS_PER_HOST: "${PROXY_MAX_IDLE_CONNS_PER_HOST:-10}"
5055
PROXY_MAX_HEADER_BYTES: "${PROXY_MAX_HEADER_BYTES:-65536}"
56+
PROXY_IDLE_CONN_TIMEOUT: "${PROXY_IDLE_CONN_TIMEOUT:-90s}"
5157
PROXY_TUNNEL_IDLE_TIMEOUT: "${PROXY_TUNNEL_IDLE_TIMEOUT:-10m}"
5258
PROXY_AUTH_MAX_FAILURES: "${PROXY_AUTH_MAX_FAILURES:-10}"
5359
PROXY_AUTH_FAILURE_WINDOW: "${PROXY_AUTH_FAILURE_WINDOW:-1m}"

internal/config/config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type Config struct {
5454
MaxConnectionsPerIP int `yaml:"max_connections_per_ip"`
5555
MaxTunnels int `yaml:"max_tunnels"`
5656
MaxTunnelsPerIP int `yaml:"max_tunnels_per_ip"`
57+
MaxIdleConns int `yaml:"max_idle_conns"`
58+
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
5759
MaxHeaderBytes int `yaml:"max_header_bytes"`
5860
AuthMaxFailures int `yaml:"auth_max_failures"`
5961
AllowPrivateDestinations bool `yaml:"allow_private_destinations"`
@@ -62,6 +64,7 @@ type Config struct {
6264
TLSHandshakeTimeout Duration `yaml:"tls_handshake_timeout"`
6365
TLSReloadInterval Duration `yaml:"tls_reload_interval"`
6466
ResponseHeaderTimeout Duration `yaml:"response_header_timeout"`
67+
IdleConnTimeout Duration `yaml:"idle_conn_timeout"`
6568
ReadHeaderTimeout Duration `yaml:"read_header_timeout"`
6669
IdleTimeout Duration `yaml:"idle_timeout"`
6770
TunnelIdleTimeout Duration `yaml:"tunnel_idle_timeout"`
@@ -84,13 +87,16 @@ func defaultConfig() Config {
8487
MaxConnectionsPerIP: 128,
8588
MaxTunnels: 256,
8689
MaxTunnelsPerIP: 128,
90+
MaxIdleConns: 100,
91+
MaxIdleConnsPerHost: 10,
8792
MaxHeaderBytes: 64 << 10,
8893
AuthMaxFailures: 10,
8994
BlockedDestinationPorts: []int{21, 22, 23, 25, 110, 111, 135, 137, 138, 139, 445, 1433, 2049, 2375, 2376, 3306, 3389, 5432, 5900, 6379, 9200, 11211, 27017},
9095
DialTimeout: Duration(10 * time.Second),
9196
TLSHandshakeTimeout: Duration(10 * time.Second),
9297
TLSReloadInterval: Duration(time.Minute),
9398
ResponseHeaderTimeout: Duration(30 * time.Second),
99+
IdleConnTimeout: Duration(90 * time.Second),
94100
ReadHeaderTimeout: Duration(15 * time.Second),
95101
IdleTimeout: Duration(2 * time.Minute),
96102
TunnelIdleTimeout: Duration(10 * time.Minute),
@@ -149,12 +155,14 @@ func decodeConfig(r io.Reader) (Config, error) {
149155
// PROXY_CERT_PATH, PROXY_KEY_PATH, PROXY_UPSTREAM_PROXY, PROXY_NETWORK,
150156
// PROXY_LOG_SENSITIVE_DATA, PROXY_MAX_CONNECTIONS,
151157
// PROXY_MAX_CONNECTIONS_PER_IP, PROXY_MAX_TUNNELS,
152-
// PROXY_MAX_TUNNELS_PER_IP, PROXY_MAX_HEADER_BYTES,
158+
// PROXY_MAX_TUNNELS_PER_IP, PROXY_MAX_IDLE_CONNS,
159+
// PROXY_MAX_IDLE_CONNS_PER_HOST, PROXY_MAX_HEADER_BYTES,
153160
// PROXY_AUTH_MAX_FAILURES, PROXY_ALLOW_PRIVATE_DESTINATIONS,
154161
// PROXY_BLOCKED_DESTINATION_PORTS,
155162
// PROXY_DIAL_TIMEOUT, PROXY_TLS_HANDSHAKE_TIMEOUT,
156163
// PROXY_TLS_RELOAD_INTERVAL,
157-
// PROXY_RESPONSE_HEADER_TIMEOUT, PROXY_READ_HEADER_TIMEOUT,
164+
// PROXY_RESPONSE_HEADER_TIMEOUT, PROXY_IDLE_CONN_TIMEOUT,
165+
// PROXY_READ_HEADER_TIMEOUT,
158166
// PROXY_IDLE_TIMEOUT, PROXY_TUNNEL_IDLE_TIMEOUT,
159167
// PROXY_AUTH_FAILURE_WINDOW, PROXY_AUTH_BLOCK_DURATION,
160168
// PROXY_SHUTDOWN_TIMEOUT.
@@ -210,6 +218,8 @@ func applyEnvOverrides(c *Config) error {
210218
{"PROXY_MAX_CONNECTIONS_PER_IP", &c.MaxConnectionsPerIP},
211219
{"PROXY_MAX_TUNNELS", &c.MaxTunnels},
212220
{"PROXY_MAX_TUNNELS_PER_IP", &c.MaxTunnelsPerIP},
221+
{"PROXY_MAX_IDLE_CONNS", &c.MaxIdleConns},
222+
{"PROXY_MAX_IDLE_CONNS_PER_HOST", &c.MaxIdleConnsPerHost},
213223
{"PROXY_MAX_HEADER_BYTES", &c.MaxHeaderBytes},
214224
{"PROXY_AUTH_MAX_FAILURES", &c.AuthMaxFailures},
215225
}
@@ -241,6 +251,7 @@ func applyEnvOverrides(c *Config) error {
241251
{"PROXY_TLS_HANDSHAKE_TIMEOUT", &c.TLSHandshakeTimeout},
242252
{"PROXY_TLS_RELOAD_INTERVAL", &c.TLSReloadInterval},
243253
{"PROXY_RESPONSE_HEADER_TIMEOUT", &c.ResponseHeaderTimeout},
254+
{"PROXY_IDLE_CONN_TIMEOUT", &c.IdleConnTimeout},
244255
{"PROXY_READ_HEADER_TIMEOUT", &c.ReadHeaderTimeout},
245256
{"PROXY_IDLE_TIMEOUT", &c.IdleTimeout},
246257
{"PROXY_TUNNEL_IDLE_TIMEOUT", &c.TunnelIdleTimeout},
@@ -293,6 +304,7 @@ func validateConfig(config *Config) error {
293304
{"tls_handshake_timeout", config.TLSHandshakeTimeout},
294305
{"tls_reload_interval", config.TLSReloadInterval},
295306
{"response_header_timeout", config.ResponseHeaderTimeout},
307+
{"idle_conn_timeout", config.IdleConnTimeout},
296308
{"read_header_timeout", config.ReadHeaderTimeout},
297309
{"idle_timeout", config.IdleTimeout},
298310
{"tunnel_idle_timeout", config.TunnelIdleTimeout},
@@ -309,6 +321,8 @@ func validateConfig(config *Config) error {
309321
{"max_connections_per_ip", config.MaxConnectionsPerIP},
310322
{"max_tunnels", config.MaxTunnels},
311323
{"max_tunnels_per_ip", config.MaxTunnelsPerIP},
324+
{"max_idle_conns", config.MaxIdleConns},
325+
{"max_idle_conns_per_host", config.MaxIdleConnsPerHost},
312326
{"max_header_bytes", config.MaxHeaderBytes},
313327
{"auth_max_failures", config.AuthMaxFailures},
314328
}

internal/config/config_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ func TestDecodeConfig(t *testing.T) {
3232
got.MaxTunnelsPerIP,
3333
)
3434
}
35+
if got.MaxIdleConns != 100 || got.MaxIdleConnsPerHost != 10 || time.Duration(got.IdleConnTimeout) != 90*time.Second {
36+
t.Errorf(
37+
"HTTP transport defaults = idle %d, idle/host %d, timeout %s; want 100, 10, 1m30s",
38+
got.MaxIdleConns,
39+
got.MaxIdleConnsPerHost,
40+
time.Duration(got.IdleConnTimeout),
41+
)
42+
}
3543
},
3644
},
3745
{
@@ -44,6 +52,8 @@ func TestDecodeConfig(t *testing.T) {
4452
"max_connections_per_ip: 20",
4553
"max_tunnels: 50",
4654
"max_tunnels_per_ip: 5",
55+
"max_idle_conns: 80",
56+
"max_idle_conns_per_host: 8",
4757
"max_header_bytes: 32768",
4858
"auth_max_failures: 7",
4959
"allow_private_destinations: true",
@@ -52,6 +62,7 @@ func TestDecodeConfig(t *testing.T) {
5262
"tls_handshake_timeout: 3s",
5363
"tls_reload_interval: 350ms",
5464
"response_header_timeout: 4s",
65+
"idle_conn_timeout: 90s",
5566
"read_header_timeout: 5s",
5667
"idle_timeout: 6m",
5768
"tunnel_idle_timeout: 8m",
@@ -78,6 +89,8 @@ func TestDecodeConfig(t *testing.T) {
7889
"MaxConnectionsPerIP": 20,
7990
"MaxTunnels": 50,
8091
"MaxTunnelsPerIP": 5,
92+
"MaxIdleConns": 80,
93+
"MaxIdleConnsPerHost": 8,
8194
"MaxHeaderBytes": 32768,
8295
"AuthMaxFailures": 7,
8396
}
@@ -86,6 +99,8 @@ func TestDecodeConfig(t *testing.T) {
8699
"MaxConnectionsPerIP": got.MaxConnectionsPerIP,
87100
"MaxTunnels": got.MaxTunnels,
88101
"MaxTunnelsPerIP": got.MaxTunnelsPerIP,
102+
"MaxIdleConns": got.MaxIdleConns,
103+
"MaxIdleConnsPerHost": got.MaxIdleConnsPerHost,
89104
"MaxHeaderBytes": got.MaxHeaderBytes,
90105
"AuthMaxFailures": got.AuthMaxFailures,
91106
}
@@ -103,6 +118,7 @@ func TestDecodeConfig(t *testing.T) {
103118
"TLSHandshakeTimeout": 3 * time.Second,
104119
"TLSReloadInterval": 350 * time.Millisecond,
105120
"ResponseHeaderTimeout": 4 * time.Second,
121+
"IdleConnTimeout": 90 * time.Second,
106122
"ReadHeaderTimeout": 5 * time.Second,
107123
"IdleTimeout": 6 * time.Minute,
108124
"TunnelIdleTimeout": 8 * time.Minute,
@@ -115,6 +131,7 @@ func TestDecodeConfig(t *testing.T) {
115131
"TLSHandshakeTimeout": time.Duration(got.TLSHandshakeTimeout),
116132
"TLSReloadInterval": time.Duration(got.TLSReloadInterval),
117133
"ResponseHeaderTimeout": time.Duration(got.ResponseHeaderTimeout),
134+
"IdleConnTimeout": time.Duration(got.IdleConnTimeout),
118135
"ReadHeaderTimeout": time.Duration(got.ReadHeaderTimeout),
119136
"IdleTimeout": time.Duration(got.IdleTimeout),
120137
"TunnelIdleTimeout": time.Duration(got.TunnelIdleTimeout),
@@ -365,6 +382,13 @@ func TestValidateConfig(t *testing.T) {
365382
},
366383
wantMessage: "response_header_timeout must be greater than zero",
367384
},
385+
{
386+
name: "nonpositive idle connection timeout",
387+
mutate: func(config *Config) {
388+
config.IdleConnTimeout = 0
389+
},
390+
wantMessage: "idle_conn_timeout must be greater than zero",
391+
},
368392
{
369393
name: "nonpositive read header timeout",
370394
mutate: func(config *Config) {
@@ -435,6 +459,20 @@ func TestValidateConfig(t *testing.T) {
435459
},
436460
wantMessage: "max_tunnels_per_ip cannot exceed max_tunnels",
437461
},
462+
{
463+
name: "nonpositive maximum idle connections",
464+
mutate: func(config *Config) {
465+
config.MaxIdleConns = 0
466+
},
467+
wantMessage: "max_idle_conns must be greater than zero",
468+
},
469+
{
470+
name: "nonpositive per-host idle connections",
471+
mutate: func(config *Config) {
472+
config.MaxIdleConnsPerHost = 0
473+
},
474+
wantMessage: "max_idle_conns_per_host must be greater than zero",
475+
},
438476
{
439477
name: "nonpositive header limit",
440478
mutate: func(config *Config) {
@@ -591,6 +629,8 @@ func TestApplyEnvOverridesParsesResourceLimits(t *testing.T) {
591629
"PROXY_MAX_CONNECTIONS_PER_IP": "20",
592630
"PROXY_MAX_TUNNELS": "50",
593631
"PROXY_MAX_TUNNELS_PER_IP": "5",
632+
"PROXY_MAX_IDLE_CONNS": "80",
633+
"PROXY_MAX_IDLE_CONNS_PER_HOST": "8",
594634
"PROXY_MAX_HEADER_BYTES": "32768",
595635
"PROXY_AUTH_MAX_FAILURES": "7",
596636
"PROXY_ALLOW_PRIVATE_DESTINATIONS": "true",
@@ -609,6 +649,9 @@ func TestApplyEnvOverridesParsesResourceLimits(t *testing.T) {
609649
if config.MaxTunnels != 50 || config.MaxTunnelsPerIP != 5 {
610650
t.Fatalf("tunnel limits = %d/%d, want 50/5", config.MaxTunnels, config.MaxTunnelsPerIP)
611651
}
652+
if config.MaxIdleConns != 80 || config.MaxIdleConnsPerHost != 8 {
653+
t.Fatalf("HTTP idle connection limits = %d/%d, want 80/8", config.MaxIdleConns, config.MaxIdleConnsPerHost)
654+
}
612655
if config.MaxHeaderBytes != 32768 || config.AuthMaxFailures != 7 {
613656
t.Fatalf("header/auth limits = %d/%d, want 32768/7", config.MaxHeaderBytes, config.AuthMaxFailures)
614657
}
@@ -692,6 +735,7 @@ func TestApplyEnvOverridesParsesDurations(t *testing.T) {
692735
{name: "TLS handshake", envName: "PROXY_TLS_HANDSHAKE_TIMEOUT", value: "11s", get: func(c Config) time.Duration { return time.Duration(c.TLSHandshakeTimeout) }, want: 11 * time.Second},
693736
{name: "TLS reload", envName: "PROXY_TLS_RELOAD_INTERVAL", value: "45s", get: func(c Config) time.Duration { return time.Duration(c.TLSReloadInterval) }, want: 45 * time.Second},
694737
{name: "response header", envName: "PROXY_RESPONSE_HEADER_TIMEOUT", value: "12s", get: func(c Config) time.Duration { return time.Duration(c.ResponseHeaderTimeout) }, want: 12 * time.Second},
738+
{name: "idle connection", envName: "PROXY_IDLE_CONN_TIMEOUT", value: "75s", get: func(c Config) time.Duration { return time.Duration(c.IdleConnTimeout) }, want: 75 * time.Second},
695739
{name: "read header", envName: "PROXY_READ_HEADER_TIMEOUT", value: "13s", get: func(c Config) time.Duration { return time.Duration(c.ReadHeaderTimeout) }, want: 13 * time.Second},
696740
{name: "idle", envName: "PROXY_IDLE_TIMEOUT", value: "3m", get: func(c Config) time.Duration { return time.Duration(c.IdleTimeout) }, want: 3 * time.Minute},
697741
{name: "tunnel idle", envName: "PROXY_TUNNEL_IDLE_TIMEOUT", value: "4m", get: func(c Config) time.Duration { return time.Duration(c.TunnelIdleTimeout) }, want: 4 * time.Minute},
@@ -725,6 +769,7 @@ func TestApplyEnvOverridesRejectsInvalidDurations(t *testing.T) {
725769
{name: "TLS handshake", envName: "PROXY_TLS_HANDSHAKE_TIMEOUT"},
726770
{name: "TLS reload", envName: "PROXY_TLS_RELOAD_INTERVAL"},
727771
{name: "response header", envName: "PROXY_RESPONSE_HEADER_TIMEOUT"},
772+
{name: "idle connection", envName: "PROXY_IDLE_CONN_TIMEOUT"},
728773
{name: "read header", envName: "PROXY_READ_HEADER_TIMEOUT"},
729774
{name: "idle", envName: "PROXY_IDLE_TIMEOUT"},
730775
{name: "tunnel idle", envName: "PROXY_TUNNEL_IDLE_TIMEOUT"},
@@ -766,6 +811,8 @@ func clearProxyEnvironment(t *testing.T) {
766811
"PROXY_MAX_CONNECTIONS_PER_IP",
767812
"PROXY_MAX_TUNNELS",
768813
"PROXY_MAX_TUNNELS_PER_IP",
814+
"PROXY_MAX_IDLE_CONNS",
815+
"PROXY_MAX_IDLE_CONNS_PER_HOST",
769816
"PROXY_MAX_HEADER_BYTES",
770817
"PROXY_AUTH_MAX_FAILURES",
771818
"PROXY_ALLOW_PRIVATE_DESTINATIONS",
@@ -774,6 +821,7 @@ func clearProxyEnvironment(t *testing.T) {
774821
"PROXY_TLS_HANDSHAKE_TIMEOUT",
775822
"PROXY_TLS_RELOAD_INTERVAL",
776823
"PROXY_RESPONSE_HEADER_TIMEOUT",
824+
"PROXY_IDLE_CONN_TIMEOUT",
777825
"PROXY_READ_HEADER_TIMEOUT",
778826
"PROXY_IDLE_TIMEOUT",
779827
"PROXY_TUNNEL_IDLE_TIMEOUT",

internal/proxy/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func NewServer(cfg config.Config) (*Server, error) {
8989
transport := &http.Transport{
9090
Proxy: proxyFunc,
9191
DisableCompression: true,
92-
MaxIdleConns: 100,
93-
MaxIdleConnsPerHost: 10,
94-
IdleConnTimeout: 90 * time.Second,
92+
MaxIdleConns: cfg.MaxIdleConns,
93+
MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost,
94+
IdleConnTimeout: time.Duration(cfg.IdleConnTimeout),
9595
TLSHandshakeTimeout: time.Duration(cfg.TLSHandshakeTimeout),
9696
ResponseHeaderTimeout: time.Duration(cfg.ResponseHeaderTimeout),
9797
ExpectContinueTimeout: time.Second,

0 commit comments

Comments
 (0)