Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/ffresty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion pkg/ffresty/ffresty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 18 additions & 0 deletions pkg/ffresty/ffresty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,21 @@ 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
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)
}