re-use transport for AdminInfo() call (#14571)

avoids creating new transport for each `isServerResolvable`
request, instead re-use the available global transport and do
not try to forcibly close connections to avoid TIME_WAIT
build upon large clusters.

Never use httpClient.CloseIdleConnections() since that can have
a drastic effect on existing connections on the transport pool.

Remove it everywhere.
This commit is contained in:
Harshavardhana 2022-03-17 16:20:10 -07:00 committed by GitHub
parent f58692abb7
commit 43eb5a001c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 5 additions and 44 deletions

View File

@ -21,7 +21,6 @@ import (
"context" "context"
crand "crypto/rand" crand "crypto/rand"
"crypto/subtle" "crypto/subtle"
"crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -2332,19 +2331,9 @@ func checkConnection(endpointStr string, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(GlobalContext, timeout) ctx, cancel := context.WithTimeout(GlobalContext, timeout)
defer cancel() defer cancel()
client := &http.Client{Transport: &http.Transport{ client := &http.Client{
Proxy: http.ProxyFromEnvironment, Transport: globalProxyTransport,
DialContext: xhttp.NewCustomDialContext(timeout), }
ResponseHeaderTimeout: 5 * time.Second,
TLSHandshakeTimeout: 5 * time.Second,
ExpectContinueTimeout: 5 * time.Second,
TLSClientConfig: &tls.Config{RootCAs: globalRootCAs},
// Go net/http automatically unzip if content-type is
// gzip disable this feature, as we are always interested
// in raw stream.
DisableCompression: true,
}}
defer client.CloseIdleConnections()
req, err := http.NewRequestWithContext(ctx, http.MethodHead, endpointStr, nil) req, err := http.NewRequestWithContext(ctx, http.MethodHead, endpointStr, nil)
if err != nil { if err != nil {

View File

@ -50,7 +50,7 @@ func getLocalServerProperty(endpointServerPools EndpointServerPools, r *http.Req
} }
_, present := network[nodeName] _, present := network[nodeName]
if !present { if !present {
if err := isServerResolvable(endpoint, 2*time.Second); err == nil { if err := isServerResolvable(endpoint, 5*time.Second); err == nil {
network[nodeName] = string(madmin.ItemOnline) network[nodeName] = string(madmin.ItemOnline)
} else { } else {
network[nodeName] = string(madmin.ItemOffline) network[nodeName] = string(madmin.ItemOffline)

View File

@ -19,7 +19,6 @@ package cmd
import ( import (
"context" "context"
"crypto/tls"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
@ -121,31 +120,9 @@ func isServerResolvable(endpoint Endpoint, timeout time.Duration) error {
Path: pathJoin(healthCheckPathPrefix, healthCheckLivenessPath), Path: pathJoin(healthCheckPathPrefix, healthCheckLivenessPath),
} }
var tlsConfig *tls.Config
if globalIsTLS {
tlsConfig = &tls.Config{
RootCAs: globalRootCAs,
}
}
httpClient := &http.Client{ httpClient := &http.Client{
Transport: Transport: globalInternodeTransport,
// For more details about various values used here refer
// https://golang.org/pkg/net/http/#Transport documentation
&http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: xhttp.NewCustomDialContext(3 * time.Second),
ResponseHeaderTimeout: 3 * time.Second,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 3 * time.Second,
TLSClientConfig: tlsConfig,
// Go net/http automatically unzip if content-type is
// gzip disable this feature, as we are always interested
// in raw stream.
DisableCompression: true,
},
} }
defer httpClient.CloseIdleConnections()
ctx, cancel := context.WithTimeout(GlobalContext, timeout) ctx, cancel := context.WithTimeout(GlobalContext, timeout)

View File

@ -63,7 +63,6 @@ type StorageAPI interface {
// returns 'nil' once healing is complete or if the disk // returns 'nil' once healing is complete or if the disk
// has never been replaced. // has never been replaced.
Healing() *healingTracker Healing() *healingTracker
DiskInfo(ctx context.Context) (info DiskInfo, err error) DiskInfo(ctx context.Context) (info DiskInfo, err error)
NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry) (dataUsageCache, error) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry) (dataUsageCache, error)

View File

@ -155,7 +155,6 @@ func (c *OperatorDNS) DeleteRecord(record SrvRecord) error {
// Close closes the internal http client // Close closes the internal http client
func (c *OperatorDNS) Close() error { func (c *OperatorDNS) Close() error {
c.httpClient.CloseIdleConnections()
return nil return nil
} }

View File

@ -471,7 +471,6 @@ func parseDiscoveryDoc(u *xnet.URL, transport *http.Transport, closeRespFn func(
} }
resp, err := clnt.Do(req) resp, err := clnt.Do(req)
if err != nil { if err != nil {
clnt.CloseIdleConnections()
return d, err return d, err
} }
defer closeRespFn(resp.Body) defer closeRespFn(resp.Body)

View File

@ -228,8 +228,6 @@ func (target *WebhookTarget) Send(eventKey string) error {
// Close - does nothing and available for interface compatibility. // Close - does nothing and available for interface compatibility.
func (target *WebhookTarget) Close() error { func (target *WebhookTarget) Close() error {
// Close idle connection with "keep-alive" states
target.httpClient.CloseIdleConnections()
return nil return nil
} }