From 5693f7b9ac477050cb33f0658eabbf3c50238145 Mon Sep 17 00:00:00 2001 From: Hu# Date: Thu, 7 Sep 2023 12:51:43 +0800 Subject: [PATCH] utils: let http client can reuse connections (#7048) Signed-off-by: husharp --- pkg/utils/etcdutil/etcdutil.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/utils/etcdutil/etcdutil.go b/pkg/utils/etcdutil/etcdutil.go index cba08c7bb99..68c0e88c9d8 100644 --- a/pkg/utils/etcdutil/etcdutil.go +++ b/pkg/utils/etcdutil/etcdutil.go @@ -270,12 +270,16 @@ func CreateEtcdClient(tlsConfig *tls.Config, acURL url.URL) (*clientv3.Client, e } func createHTTPClient(tlsConfig *tls.Config) *http.Client { - return &http.Client{ - Transport: &http.Transport{ - DisableKeepAlives: true, - TLSClientConfig: tlsConfig, - }, + // FIXME: Currently, there is no timeout set for certain requests, such as GetRegions, + // which may take a significant amount of time. However, it might be necessary to + // define an appropriate timeout in the future. + cli := &http.Client{} + if tlsConfig != nil { + transport := http.DefaultTransport.(*http.Transport).Clone() + transport.TLSClientConfig = tlsConfig + cli.Transport = transport } + return cli } // InitClusterID creates a cluster ID for the given key if it hasn't existed.