Skip to content

Commit 7ab7a24

Browse files
authored
Use custom http.Client for AWS (#537)
1 parent eef0958 commit 7ab7a24

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pkg/chunk/aws_storage_client.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"io/ioutil"
88
"math/rand"
9+
"net"
10+
"net/http"
911
"net/url"
1012
"strings"
1113
"time"
@@ -830,7 +832,25 @@ func awsConfigFromURL(awsURL *url.URL) (*aws.Config, error) {
830832
creds := credentials.NewStaticCredentials(awsURL.User.Username(), password, "")
831833
config := aws.NewConfig().
832834
WithCredentials(creds).
833-
WithMaxRetries(0) // We do our own retries, so we can monitor them
835+
WithMaxRetries(0). // We do our own retries, so we can monitor them
836+
// Use a custom http.Client with the golang defaults but also specifying
837+
// MaxIdleConnsPerHost because of a bug in golang https://github.com/golang/go/issues/13801
838+
// where MaxIdleConnsPerHost does not work as expected.
839+
WithHTTPClient(&http.Client{
840+
Transport: &http.Transport{
841+
Proxy: http.ProxyFromEnvironment,
842+
DialContext: (&net.Dialer{
843+
Timeout: 30 * time.Second,
844+
KeepAlive: 30 * time.Second,
845+
DualStack: true,
846+
}).DialContext,
847+
MaxIdleConns: 100,
848+
IdleConnTimeout: 90 * time.Second,
849+
MaxIdleConnsPerHost: 100,
850+
TLSHandshakeTimeout: 3 * time.Second,
851+
ExpectContinueTimeout: 1 * time.Second,
852+
},
853+
})
834854
if strings.Contains(awsURL.Host, ".") {
835855
return config.WithEndpoint(fmt.Sprintf("http://%s", awsURL.Host)).WithRegion("dummy"), nil
836856
}

0 commit comments

Comments
 (0)