Skip to content

Commit

Permalink
prevent vtctld from creating tons of S3 connections
Browse files Browse the repository at this point in the history
Signed-off-by: Renan Rangel <[email protected]>
  • Loading branch information
rvrangel committed Feb 20, 2024
1 parent f1a95e1 commit dcdb7cf
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions go/vt/mysqlctl/s3backupstorage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ var (

// path component delimiter
delimiter = "/"

// use a shared transport for all connections
defaultS3Transport *http.Transport
)

func registerFlags(fs *pflag.FlagSet) {
Expand Down Expand Up @@ -445,9 +448,7 @@ func (bs *S3BackupStorage) client() (*s3.S3, error) {
if bs._client == nil {
logLevel := getLogLevel()

tlsClientConf := &tls.Config{InsecureSkipVerify: tlsSkipVerifyCert}
httpTransport := &http.Transport{TLSClientConfig: tlsClientConf}
httpClient := &http.Client{Transport: httpTransport}
httpClient := &http.Client{Transport: getS3Transport()}

session, err := session.NewSession()
if err != nil {
Expand Down Expand Up @@ -496,6 +497,19 @@ func objName(parts ...string) *string {
return &res
}

// This creates a new transport based off http.DefaultTransport the first time and returns the same
// transport on subsequent calls so connections can be reused as part of the same transport.
func getS3Transport() *http.Transport {
if defaultS3Transport == nil {
tlsClientConf := &tls.Config{InsecureSkipVerify: tlsSkipVerifyCert}

defaultS3Transport = http.DefaultTransport.(*http.Transport).Clone()
defaultS3Transport.TLSClientConfig = tlsClientConf
}

return defaultS3Transport
}

func init() {
backupstorage.BackupStorageMap["s3"] = &S3BackupStorage{params: backupstorage.NoParams()}

Expand Down

0 comments on commit dcdb7cf

Please sign in to comment.