Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Fix mutex protection on TLS pool #63

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions internal/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ func NewTLSConfigPool(ctx context.Context) TLSConfigPool {

// LoadTLSConfig loads a TLS configuration from the given TLSConfig.
func (p *tlsConfigPool) LoadTLSConfig(config TLSConfig) (*tls.Config, error) {
if config.GetTrustedCertificateAuthority() == "" &&
config.GetTrustedCertificateAuthorityFile() == "" &&
config.GetSkipVerifyPeerCert() == nil {
// no given TLS config, nothing to load
return nil, nil
}

encConfig := encodeConfig(config)
id := encConfig.hash()

p.mu.Lock()
if tlsConfig, ok := p.configs[id]; ok {
p.mu.Unlock()
return tlsConfig, nil
}
p.mu.Unlock()

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

case config.GetSkipVerifyPeerCert() != nil:
tlsConfig.InsecureSkipVerify = BoolStrValue(config.GetSkipVerifyPeerCert())

default:
// No CA or skip verification, return nil TLS config
return nil, nil
}

// Add the loaded CA to the TLS config
Expand Down