From 9670bc14f88d835dca248dc030a7001dc773350b Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Fri, 21 May 2021 21:06:59 +0200 Subject: [PATCH] fix unsafe dereference --- store/http.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/store/http.go b/store/http.go index f79612e..c24169a 100644 --- a/store/http.go +++ b/store/http.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "io/ioutil" + "net" "net/http" "sync" "time" @@ -140,14 +141,20 @@ func putBuffer(buf *bytes.Buffer) { // getClient gets an http client that's customized to be more performant when dealing with blobs of 2MB in size (most of our blobs) func getClient() *http.Client { // Customize the Transport to have larger connection pool - defaultRoundTripper := http.DefaultTransport - defaultTransportPointer := defaultRoundTripper.(*http.Transport) + defaultTransport := &http.Transport{ + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + DisableCompression: true, + MaxIdleConnsPerHost: 100, + ReadBufferSize: stream.MaxBlobSize + 1024*10, //add an extra few KBs to make sure it fits the extra information + } - defaultTransport := *defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to - defaultTransport.MaxIdleConns = 100 - defaultTransport.DisableCompression = true - defaultTransport.MaxIdleConnsPerHost = 100 - defaultTransport.ReadBufferSize = stream.MaxBlobSize + 1024*10 //add an extra few KBs to make sure it fits the extra information - - return &http.Client{Transport: &defaultTransport} + return &http.Client{Transport: defaultTransport} }