mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
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:
parent
f58692abb7
commit
43eb5a001c
@ -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 {
|
||||||
|
@ -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)
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user