Repository navigation
Conversation
…onfig StartConfig.StartTLS uses a value receiver, so callers can safely reuse a base *tls.Config across listeners or servers. Previously, when sc.TLSConfig was non-nil, StartTLS assigned sc.TLSConfig.Certificates directly on the caller's pointer without cloning it, which mutated the caller's *tls.Config and caused a data race under -race when multiple StartTLS calls shared a base *tls.Config. Clone sc.TLSConfig via sc.TLSConfig.Clone() before setting Certificates, and add unit and concurrent -race regression tests in server_tls_test.go.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
Summary
Clone caller-provided
StartConfig.TLSConfiginsideStartConfig.StartTLSbefore settingCertificates, preventing in-place mutation of the caller's*tls.Configand eliminating a data race when multipleStartTLScalls share a base*tls.Config.Root Cause
StartConfig.StartTLS(server.go) has a value receiver, so callers can reuse a shared base*tls.Config(for example with commonMinVersion,CipherSuites, orNextProtos) across multiple servers or listeners. Previously, whensc.TLSConfig != nil,StartTLSwrote:directly onto the caller's
*tls.Configwithout callingsc.TLSConfig.Clone(). This:*tls.Configin place (clobbering itsCertificatesslice).go test -racewhen twoStartTLScalls run concurrently with the same base*tls.Config.Fix
sc.TLSConfigviasc.TLSConfig.Clone()before assigningCertificatesinStartConfig.StartTLS(server.go).server_tls_test.gocovering both single-server non-mutation and concurrentStartTLScalls sharing a base*tls.Configunder-race.Verification
go test -race -v -count=1 . -run '^TestStartConfig_StartTLS_(DoesNotMutateCallerTLSConfig|SharedTLSConfigConcurrent)$'(fails before the fix withCertificatesmutation and a-racedata race; passes after the fix).go test -race -count=1 .go vet ./...Summary by CodeRabbit