Skip to content

Commit 28ae8dc

Browse files
authored
Fix mutex protection on TLS pool (istio-ecosystem#63)
And avoid confusing log if TLS is not required
1 parent 090a9bd commit 28ae8dc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: internal/tls.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,22 @@ func NewTLSConfigPool(ctx context.Context) TLSConfigPool {
7373

7474
// LoadTLSConfig loads a TLS configuration from the given TLSConfig.
7575
func (p *tlsConfigPool) LoadTLSConfig(config TLSConfig) (*tls.Config, error) {
76+
if config.GetTrustedCertificateAuthority() == "" &&
77+
config.GetTrustedCertificateAuthorityFile() == "" &&
78+
config.GetSkipVerifyPeerCert() == nil {
79+
// no given TLS config, nothing to load
80+
return nil, nil
81+
}
82+
7683
encConfig := encodeConfig(config)
7784
id := encConfig.hash()
85+
86+
p.mu.Lock()
7887
if tlsConfig, ok := p.configs[id]; ok {
88+
p.mu.Unlock()
7989
return tlsConfig, nil
8090
}
91+
p.mu.Unlock()
8192

8293
log := p.log.With("id", id)
8394
log.Info("loading new TLS config", "config", encConfig.JSON())
@@ -102,10 +113,6 @@ func (p *tlsConfigPool) LoadTLSConfig(config TLSConfig) (*tls.Config, error) {
102113

103114
case config.GetSkipVerifyPeerCert() != nil:
104115
tlsConfig.InsecureSkipVerify = BoolStrValue(config.GetSkipVerifyPeerCert())
105-
106-
default:
107-
// No CA or skip verification, return nil TLS config
108-
return nil, nil
109116
}
110117

111118
// Add the loaded CA to the TLS config

0 commit comments

Comments
 (0)