@@ -11,6 +11,7 @@ import (
1111 "net/url"
1212 "slices"
1313 "strings"
14+ "sync"
1415 "time"
1516
1617 "github.com/zmap/zcrypto/x509"
@@ -27,7 +28,8 @@ type PKIMetalConfig struct {
2728 Timeout time.Duration `toml:"timeout" comment:"How long, in nanoseconds, to wait before giving up."`
2829 IgnoreLints []string `toml:"ignore_lints" comment:"The unique Validator:Code IDs of lint findings which should be ignored."`
2930
30- client * http.Client
31+ client * http.Client
32+ clientOnce sync.Once
3133}
3234
3335func (pkim * PKIMetalConfig ) execute (endpoint string , der []byte ) (* lint.LintResult , error ) {
@@ -36,11 +38,9 @@ func (pkim *PKIMetalConfig) execute(endpoint string, der []byte) (*lint.LintResu
3638 timeout = 100 * time .Millisecond
3739 }
3840
39- // Initialize HTTP client once and reuse it for connection pooling
40- if pkim .client == nil {
41- pkim .client = & http.Client {
42- Timeout : timeout ,
43- }
41+ // Initialize HTTP client once with thread-safe sync.Once for connection pooling
42+ pkim .clientOnce .Do (func () {
43+ pkim .client = & http.Client {}
4444 // If using Unix socket, set up custom transport
4545 if pkim .Socket != "" {
4646 pkim .client .Transport = & http.Transport {
@@ -49,7 +49,7 @@ func (pkim *PKIMetalConfig) execute(endpoint string, der []byte) (*lint.LintResu
4949 },
5050 }
5151 }
52- }
52+ })
5353
5454 ctx , cancel := context .WithTimeout (context .Background (), timeout )
5555 defer cancel ()
0 commit comments