Parcourir la source

SslOptions: embed a pointer to the TLS config (#891)

* SslOptions: embed a pointer to the TLS config

This embeds a pointer to the desired TLS config instead of a concrete
value. Because Go copies the arguments of all function calls, this has the side effect of copying the TLS configuration, which copies a mutex. This causes
`go vet` to report that `crypto/tls.Config contains sync.Once contains sync.Mutex`.

This patch removes this complaint, but at the cost of needing people to change
their cassandra TLS configuration code to remove the dereference of the TLS
config.

* connectionpool: fix build

* setupTLSConfig: create TLS config if it does not exist
Christine Dodrill il y a 8 ans
Parent
commit
66628b367c
2 fichiers modifiés avec 6 ajouts et 2 suppressions
  1. 1 1
      conn.go
  2. 5 1
      connectionpool.go

+ 1 - 1
conn.go

@@ -79,7 +79,7 @@ func (p PasswordAuthenticator) Success(data []byte) error {
 }
 
 type SslOptions struct {
-	tls.Config
+	*tls.Config
 
 	// CertPath and KeyPath are optional depending on server
 	// config, but both fields must be omitted to avoid using a

+ 5 - 1
connectionpool.go

@@ -28,6 +28,10 @@ type SetPartitioner interface {
 }
 
 func setupTLSConfig(sslOpts *SslOptions) (*tls.Config, error) {
+	if sslOpts.Config == nil {
+		sslOpts.Config = &tls.Config{}
+	}
+
 	// ca cert is optional
 	if sslOpts.CaPath != "" {
 		if sslOpts.RootCAs == nil {
@@ -54,7 +58,7 @@ func setupTLSConfig(sslOpts *SslOptions) (*tls.Config, error) {
 
 	sslOpts.InsecureSkipVerify = !sslOpts.EnableHostVerification
 
-	return &sslOpts.Config, nil
+	return sslOpts.Config, nil
 }
 
 type policyConnPool struct {