File tree 2 files changed +16
-3
lines changed
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -506,9 +506,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
506
506
return fmt .Errorf ("invalid value for TLS config name: %v" , err )
507
507
}
508
508
509
- if tlsConfig , ok := tlsConfigRegister [name ]; ok {
510
- tlsConfig = cloneTLSConfig (tlsConfig )
511
-
509
+ if tlsConfig := getTLSConfigClone (name ); tlsConfig != nil {
512
510
if len (tlsConfig .ServerName ) == 0 && ! tlsConfig .InsecureSkipVerify {
513
511
host , _ , err := net .SplitHostPort (cfg .Addr )
514
512
if err == nil {
Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ import (
16
16
"fmt"
17
17
"io"
18
18
"strings"
19
+ "sync"
19
20
"time"
20
21
)
21
22
22
23
var (
24
+ tlsConfigLock sync.RWMutex
23
25
tlsConfigRegister map [string ]* tls.Config // Register for custom tls.Configs
24
26
)
25
27
@@ -53,19 +55,32 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
53
55
return fmt .Errorf ("key '%s' is reserved" , key )
54
56
}
55
57
58
+ tlsConfigLock .Lock ()
56
59
if tlsConfigRegister == nil {
57
60
tlsConfigRegister = make (map [string ]* tls.Config )
58
61
}
59
62
60
63
tlsConfigRegister [key ] = config
64
+ tlsConfigLock .Unlock ()
61
65
return nil
62
66
}
63
67
64
68
// DeregisterTLSConfig removes the tls.Config associated with key.
65
69
func DeregisterTLSConfig (key string ) {
70
+ tlsConfigLock .Lock ()
66
71
if tlsConfigRegister != nil {
67
72
delete (tlsConfigRegister , key )
68
73
}
74
+ tlsConfigLock .Unlock ()
75
+ }
76
+
77
+ func getTLSConfigClone (key string ) (config * tls.Config ) {
78
+ tlsConfigLock .RLock ()
79
+ if v , ok := tlsConfigRegister [key ]; ok {
80
+ config = cloneTLSConfig (v )
81
+ }
82
+ tlsConfigLock .RUnlock ()
83
+ return
69
84
}
70
85
71
86
// Returns the bool value of the input.
You can’t perform that action at this time.
0 commit comments