Skip to content

Commit 8b16e13

Browse files
committed
Use sync.Mutex when updating the customTLSConfigMap
I've not noticed any data race issues, but just to be a bit safer.
1 parent 039dcc2 commit 8b16e13

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

driver/driver.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
"io"
1111
"net/url"
1212
"regexp"
13+
"sync"
1314

1415
"github.com/go-mysql-org/go-mysql/client"
1516
"github.com/go-mysql-org/go-mysql/mysql"
1617
"github.com/pingcap/errors"
1718
"github.com/siddontang/go/hack"
1819
)
1920

21+
var customTLSMutex sync.Mutex
2022
// Map of dsn address (makes more sense than full dsn?) to tls Config
2123
var customTLSConfigMap = make(map[string]*tls.Config)
2224

@@ -315,8 +317,10 @@ func SetCustomTLSConfig(dsn string, caPem []byte, certPem []byte, keyPem []byte,
315317
// having multiple CA certs for one hostname is likely when you have services running on
316318
// different ports.
317319

320+
customTLSMutex.Lock()
318321
// Basic pass-through function so we can just import the driver
319322
customTLSConfigMap[addr] = client.NewClientTLSConfig(caPem, certPem, keyPem, insecureSkipVerify, serverName)
323+
customTLSMutex.Unlock()
320324

321325
return nil
322326
}

0 commit comments

Comments
 (0)