From 78a2e33ecd35f52ede99fb01d2268561b21db090 Mon Sep 17 00:00:00 2001 From: hfuss Date: Sat, 5 Sep 2026 18:03:22 -0400 Subject: [PATCH 1/2] fix(ffresty): Set the correct maxIdleConnHosts value and idleTimeout Signed-off-by: hfuss --- pkg/ffresty/config.go | 2 +- pkg/ffresty/ffresty.go | 2 +- pkg/ffresty/ffresty_test.go | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/ffresty/config.go b/pkg/ffresty/config.go index ecd9fbe..a4cf51f 100644 --- a/pkg/ffresty/config.go +++ b/pkg/ffresty/config.go @@ -32,7 +32,7 @@ const ( defaultRetryWaitTime = "250ms" defaultRetryMaxWaitTime = "30s" defaultRequestTimeout = "30s" - defaultHTTPIdleTimeout = "475ms" // Node.js default keepAliveTimeout is 5 seconds, so we have to set a base below this + defaultHTTPIdleTimeout = "4750ms" // Node.js default keepAliveTimeout is 5 seconds, so we have to set a base below this (was a 475ms typo for years) defaultHTTPMaxIdleConns = 100 // match Go's default defaultHTTPMaxConnsPerHost = 0 // unlimited defaultHTTPMaxIdleConnsPerHost = 100 // avoid Go's conservative default of 2, we'd rather it be the same as the maxIdleConns so a single host can use all the connections diff --git a/pkg/ffresty/ffresty.go b/pkg/ffresty/ffresty.go index 6972726..4b150dd 100644 --- a/pkg/ffresty/ffresty.go +++ b/pkg/ffresty/ffresty.go @@ -232,7 +232,7 @@ func NewWithConfig(ctx context.Context, ffrestyConfig Config) (client *resty.Cli ForceAttemptHTTP2: true, MaxIdleConns: ffrestyConfig.HTTPMaxIdleConns, MaxConnsPerHost: ffrestyConfig.HTTPMaxConnsPerHost, - MaxIdleConnsPerHost: ffrestyConfig.HTTPMaxConnsPerHost, + MaxIdleConnsPerHost: ffrestyConfig.HTTPMaxIdleConnsPerHost, IdleConnTimeout: time.Duration(ffrestyConfig.HTTPIdleConnTimeout), TLSHandshakeTimeout: time.Duration(ffrestyConfig.HTTPTLSHandshakeTimeout), ExpectContinueTimeout: time.Duration(ffrestyConfig.HTTPExpectContinueTimeout), diff --git a/pkg/ffresty/ffresty_test.go b/pkg/ffresty/ffresty_test.go index 108243e..83653c6 100644 --- a/pkg/ffresty/ffresty_test.go +++ b/pkg/ffresty/ffresty_test.go @@ -863,3 +863,22 @@ func TestGenerateConfigDNSResolver(t *testing.T) { assert.NoError(t, err) assert.Nil(t, cfg.Resolver) } + +func TestNewTransportPoolSettingsFromConfig(t *testing.T) { + // The idle pool is sized from maxIdleConnsPerHost, independently of the (unlimited by + // default) maxConnsPerHost - a zero MaxIdleConnsPerHost would silently fall back to Go's + // default of 2 idle connections per host. + resetConf() + utConf.Set(HTTPConfigURL, "http://localhost:12345") + utConf.Set(HTTPMaxConnsPerHost, 0) + utConf.Set(HTTPMaxIdleConnsPerHost, 42) + utConf.Set(HTTPMaxIdleConns, 84) + c, err := New(context.Background(), utConf) + require.NoError(t, err) + transport, ok := c.GetClient().Transport.(*http.Transport) + require.True(t, ok) + assert.Equal(t, 0, transport.MaxConnsPerHost) + assert.Equal(t, 42, transport.MaxIdleConnsPerHost) + assert.Equal(t, 84, transport.MaxIdleConns) + assert.True(t, transport.ForceAttemptHTTP2) +} From 3cf580293bbe2e2f4654e438972f130acf50cea2 Mon Sep 17 00:00:00 2001 From: hfuss Date: Sat, 5 Sep 2026 18:16:32 -0400 Subject: [PATCH 2/2] fix formatting and comments Signed-off-by: hfuss --- pkg/ffresty/config.go | 8 ++++---- pkg/ffresty/ffresty_test.go | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/ffresty/config.go b/pkg/ffresty/config.go index a4cf51f..9adb420 100644 --- a/pkg/ffresty/config.go +++ b/pkg/ffresty/config.go @@ -32,10 +32,10 @@ const ( defaultRetryWaitTime = "250ms" defaultRetryMaxWaitTime = "30s" defaultRequestTimeout = "30s" - defaultHTTPIdleTimeout = "4750ms" // Node.js default keepAliveTimeout is 5 seconds, so we have to set a base below this (was a 475ms typo for years) - defaultHTTPMaxIdleConns = 100 // match Go's default - defaultHTTPMaxConnsPerHost = 0 // unlimited - defaultHTTPMaxIdleConnsPerHost = 100 // avoid Go's conservative default of 2, we'd rather it be the same as the maxIdleConns so a single host can use all the connections + defaultHTTPIdleTimeout = "4750ms" // Node.js default keepAliveTimeout is 5 seconds, so we have to set a base below this + defaultHTTPMaxIdleConns = 100 // match Go's default + defaultHTTPMaxConnsPerHost = 0 // unlimited + defaultHTTPMaxIdleConnsPerHost = 100 // avoid Go's conservative default of 2, we'd rather it be the same as the maxIdleConns so a single host can use all the connections defaultHTTPConnectionTimeout = "30s" defaultHTTPTLSHandshakeTimeout = "10s" // match Go's default defaultHTTPExpectContinueTimeout = "1s" // match Go's default diff --git a/pkg/ffresty/ffresty_test.go b/pkg/ffresty/ffresty_test.go index 83653c6..75f87fe 100644 --- a/pkg/ffresty/ffresty_test.go +++ b/pkg/ffresty/ffresty_test.go @@ -866,8 +866,7 @@ func TestGenerateConfigDNSResolver(t *testing.T) { func TestNewTransportPoolSettingsFromConfig(t *testing.T) { // The idle pool is sized from maxIdleConnsPerHost, independently of the (unlimited by - // default) maxConnsPerHost - a zero MaxIdleConnsPerHost would silently fall back to Go's - // default of 2 idle connections per host. + // default) maxConnsPerHost resetConf() utConf.Set(HTTPConfigURL, "http://localhost:12345") utConf.Set(HTTPMaxConnsPerHost, 0)