mirror of
https://github.com/minio/minio.git
synced 2025-04-16 00:49:09 -04:00
Avoid using a nil transport when the config is not initialized (#19405)
Make sure to pass a nil pointer as a Transport to minio-go when the API config is not initialized, this will make sure that we do not pass an interface with a known type but a nil value. This will also fix the update of the API remote_transport_deadline configuration without requiring the cluster restart.
This commit is contained in:
parent
d7daae4762
commit
97ce11cb6b
@ -321,7 +321,7 @@ func (r BatchJobExpire) Notify(ctx context.Context, body io.Reader) error {
|
|||||||
req.Header.Set("Authorization", r.NotificationCfg.Token)
|
req.Header.Set("Authorization", r.NotificationCfg.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
clnt := http.Client{Transport: getRemoteInstanceTransport}
|
clnt := http.Client{Transport: getRemoteInstanceTransport()}
|
||||||
resp, err := clnt.Do(req)
|
resp, err := clnt.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -92,7 +92,7 @@ func notifyEndpoint(ctx context.Context, ri *batchJobInfo, endpoint, token strin
|
|||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
clnt := http.Client{Transport: getRemoteInstanceTransport}
|
clnt := http.Client{Transport: getRemoteInstanceTransport()}
|
||||||
resp, err := clnt.Do(req)
|
resp, err := clnt.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -351,7 +351,7 @@ func (r *BatchJobReplicateV1) StartFromSource(ctx context.Context, api ObjectLay
|
|||||||
c, err := miniogo.New(u.Host, &miniogo.Options{
|
c, err := miniogo.New(u.Host, &miniogo.Options{
|
||||||
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
||||||
Secure: u.Scheme == "https",
|
Secure: u.Scheme == "https",
|
||||||
Transport: getRemoteInstanceTransport,
|
Transport: getRemoteInstanceTransport(),
|
||||||
BucketLookup: lookupStyle(r.Source.Path),
|
BucketLookup: lookupStyle(r.Source.Path),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1048,7 +1048,7 @@ func (r *BatchJobReplicateV1) Start(ctx context.Context, api ObjectLayer, job Ba
|
|||||||
c, err := miniogo.NewCore(u.Host, &miniogo.Options{
|
c, err := miniogo.NewCore(u.Host, &miniogo.Options{
|
||||||
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
||||||
Secure: u.Scheme == "https",
|
Secure: u.Scheme == "https",
|
||||||
Transport: getRemoteInstanceTransport,
|
Transport: getRemoteInstanceTransport(),
|
||||||
BucketLookup: lookupStyle(r.Target.Path),
|
BucketLookup: lookupStyle(r.Target.Path),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1068,7 +1068,7 @@ func (r *BatchJobReplicateV1) Start(ctx context.Context, api ObjectLayer, job Ba
|
|||||||
cl, err := miniogo.New(u.Host, &miniogo.Options{
|
cl, err := miniogo.New(u.Host, &miniogo.Options{
|
||||||
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
||||||
Secure: u.Scheme == "https",
|
Secure: u.Scheme == "https",
|
||||||
Transport: getRemoteInstanceTransport,
|
Transport: getRemoteInstanceTransport(),
|
||||||
BucketLookup: lookupStyle(r.Target.Path),
|
BucketLookup: lookupStyle(r.Target.Path),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1354,7 +1354,7 @@ func (r *BatchJobReplicateV1) Validate(ctx context.Context, job BatchJobRequest,
|
|||||||
c, err := miniogo.NewCore(u.Host, &miniogo.Options{
|
c, err := miniogo.NewCore(u.Host, &miniogo.Options{
|
||||||
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, cred.SessionToken),
|
||||||
Secure: u.Scheme == "https",
|
Secure: u.Scheme == "https",
|
||||||
Transport: getRemoteInstanceTransport,
|
Transport: getRemoteInstanceTransport(),
|
||||||
BucketLookup: lookupStyle(pathStyle),
|
BucketLookup: lookupStyle(pathStyle),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -576,11 +576,7 @@ func applyDynamicConfigForSubSys(ctx context.Context, objAPI ObjectLayer, s conf
|
|||||||
|
|
||||||
globalAPIConfig.init(apiConfig, setDriveCounts)
|
globalAPIConfig.init(apiConfig, setDriveCounts)
|
||||||
autoGenerateRootCredentials() // Generate the KMS root credentials here since we don't know whether API root access is disabled until now.
|
autoGenerateRootCredentials() // Generate the KMS root credentials here since we don't know whether API root access is disabled until now.
|
||||||
|
setRemoteInstanceTransport(NewHTTPTransportWithTimeout(apiConfig.RemoteTransportDeadline))
|
||||||
// Initialize remote instance transport once.
|
|
||||||
getRemoteInstanceTransportOnce.Do(func() {
|
|
||||||
getRemoteInstanceTransport = NewHTTPTransportWithTimeout(apiConfig.RemoteTransportDeadline)
|
|
||||||
})
|
|
||||||
case config.CompressionSubSys:
|
case config.CompressionSubSys:
|
||||||
cmpCfg, err := compress.LookupConfig(s[config.CompressionSubSys][config.Default])
|
cmpCfg, err := compress.LookupConfig(s[config.CompressionSubSys][config.Default])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@ -1291,11 +1291,20 @@ func getCpObjMetadataFromHeader(ctx context.Context, r *http.Request, userMeta m
|
|||||||
return defaultMeta, nil
|
return defaultMeta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRemoteInstanceTransport contains a singleton roundtripper.
|
// getRemoteInstanceTransport contains a roundtripper for external (not peers) servers
|
||||||
var (
|
var remoteInstanceTransport atomic.Value
|
||||||
getRemoteInstanceTransport *http.Transport
|
|
||||||
getRemoteInstanceTransportOnce sync.Once
|
func setRemoteInstanceTransport(tr http.RoundTripper) {
|
||||||
)
|
remoteInstanceTransport.Store(tr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRemoteInstanceTransport() http.RoundTripper {
|
||||||
|
rt, ok := remoteInstanceTransport.Load().(http.RoundTripper)
|
||||||
|
if ok {
|
||||||
|
return rt
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a minio-go Client configured to access remote host described by destDNSRecord
|
// Returns a minio-go Client configured to access remote host described by destDNSRecord
|
||||||
// Applicable only in a federated deployment
|
// Applicable only in a federated deployment
|
||||||
@ -1306,7 +1315,7 @@ var getRemoteInstanceClient = func(r *http.Request, host string) (*miniogo.Core,
|
|||||||
core, err := miniogo.NewCore(host, &miniogo.Options{
|
core, err := miniogo.NewCore(host, &miniogo.Options{
|
||||||
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, ""),
|
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, ""),
|
||||||
Secure: globalIsTLS,
|
Secure: globalIsTLS,
|
||||||
Transport: getRemoteInstanceTransport,
|
Transport: getRemoteInstanceTransport(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user