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:
Anis Eleuch
2024-04-03 19:27:05 +01:00
committed by GitHub
parent d7daae4762
commit 97ce11cb6b
4 changed files with 23 additions and 18 deletions
+16 -7
View File
@@ -34,7 +34,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"unicode"
@@ -1291,11 +1291,20 @@ func getCpObjMetadataFromHeader(ctx context.Context, r *http.Request, userMeta m
return defaultMeta, nil
}
// getRemoteInstanceTransport contains a singleton roundtripper.
var (
getRemoteInstanceTransport *http.Transport
getRemoteInstanceTransportOnce sync.Once
)
// getRemoteInstanceTransport contains a roundtripper for external (not peers) servers
var remoteInstanceTransport atomic.Value
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
// 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{
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, ""),
Secure: globalIsTLS,
Transport: getRemoteInstanceTransport,
Transport: getRemoteInstanceTransport(),
})
if err != nil {
return nil, err