From 53111d1d1626eff0e48468b798acaec61486dbcd Mon Sep 17 00:00:00 2001 From: DQ Date: Thu, 16 Apr 2020 22:40:48 +0800 Subject: [PATCH] Fix: Default Transport HTTP2 related hang issue Create a transport the same as default except forceattempthttp2 Signed-off-by: DQ --- src/common/http/client.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/common/http/client.go b/src/common/http/client.go index 2c6099a34..42cd6c223 100644 --- a/src/common/http/client.go +++ b/src/common/http/client.go @@ -16,13 +16,16 @@ package http import ( "bytes" + "crypto/tls" "encoding/json" "errors" "io" "io/ioutil" + "net" "net/http" "net/url" "reflect" + "time" "github.com/goharbor/harbor/src/common/http/modifier" "github.com/goharbor/harbor/src/lib" @@ -41,8 +44,8 @@ var ( ) func init() { - secureHTTPTransport = http.DefaultTransport.(*http.Transport).Clone() - insecureHTTPTransport = http.DefaultTransport.(*http.Transport).Clone() + secureHTTPTransport = newDefaultTransport() + insecureHTTPTransport = newDefaultTransport() insecureHTTPTransport.TLSClientConfig.InsecureSkipVerify = true if InternalTLSEnabled() { @@ -54,6 +57,22 @@ func init() { } } +func newDefaultTransport() *http.Transport { + return &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + TLSClientConfig: &tls.Config{}, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + } +} + // Client is a util for common HTTP operations, such Get, Head, Post, Put and Delete. // Use Do instead if those methods can not meet your requirement type Client struct {