Skip to content

Commit c8ec89c

Browse files
authored
[minor_change] Increase connection pool and enable TLS session ticket caching (#151)
1 parent 97a0271 commit c8ec89c

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

client/client.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,30 @@ func (c *Client) configProxy(transport *http.Transport) *http.Transport {
186186
}
187187

188188
func (c *Client) useInsecureHTTPClient(insecure bool) *http.Transport {
189-
transport := &http.Transport{
190-
TLSClientConfig: &tls.Config{
191-
CipherSuites: []uint16{
192-
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
193-
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
194-
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
195-
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
196-
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
197-
},
198-
PreferServerCipherSuites: true,
199-
InsecureSkipVerify: insecure,
200-
MinVersion: tls.VersionTLS11,
201-
MaxVersion: tls.VersionTLS13,
189+
// Clone http.DefaultTransport instead of mutating the global default,
190+
// preventing side effects on other HTTP clients in the same process
191+
transport := http.DefaultTransport.(*http.Transport).Clone()
192+
193+
// Increase from the default (2) to 32, ensuring Terraform's default
194+
// parallelism of 10 concurrent operations can reuse idle
195+
// connections instead of repeatedly opening new ones
196+
transport.MaxIdleConnsPerHost = 32
197+
transport.TLSClientConfig = &tls.Config{
198+
CipherSuites: []uint16{
199+
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
200+
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
201+
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
202+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
203+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
202204
},
205+
PreferServerCipherSuites: true,
206+
InsecureSkipVerify: insecure,
207+
// Enable TLS client session caching to allow TLS session ticket resumption,
208+
// avoiding the overhead of TLS handshake for subsequent requests to the
209+
// same server.
210+
ClientSessionCache: tls.NewLRUClientSessionCache(0),
211+
MinVersion: tls.VersionTLS11,
212+
MaxVersion: tls.VersionTLS13,
203213
}
204214

205215
return transport

0 commit comments

Comments
 (0)