Skip to content

Commit

Permalink
Merge pull request #739 from luraproject/remove-race-warnings
Browse files Browse the repository at this point in the history
Remove race warnings
  • Loading branch information
kpacha authored Dec 10, 2024
2 parents d44d87e + 7272f8d commit f8a0bc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 7 additions & 5 deletions proxy/shadow.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ func (s shadowFactory) New(cfg *config.EndpointConfig) (p Proxy, err error) {
return
}

cfgCopy := *cfg

var shadow []*config.Backend
var regular []*config.Backend
var maxTimeout time.Duration
for _, b := range cfg.Backend {
for _, b := range cfgCopy.Backend {
if d, ok := isShadowBackend(b); ok {
if maxTimeout < d {
maxTimeout = d
Expand All @@ -42,12 +44,12 @@ func (s shadowFactory) New(cfg *config.EndpointConfig) (p Proxy, err error) {
regular = append(regular, b)
}

cfg.Backend = regular
p, err = s.f.New(cfg)
cfgCopy.Backend = regular
p, err = s.f.New(&cfgCopy)

if len(shadow) > 0 {
cfg.Backend = shadow
pShadow, _ := s.f.New(cfg)
cfgCopy.Backend = shadow
pShadow, _ := s.f.New(&cfgCopy)
p = ShadowMiddlewareWithTimeout(maxTimeout, p, pShadow)
}

Expand Down
4 changes: 2 additions & 2 deletions transport/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func InitHTTPDefaultTransportWithLogger(cfg config.ServiceConfig, logger logging
cfg.ClientTLS.AllowInsecureConnections = true
}
onceTransportConfig.Do(func() {
http.DefaultTransport = newTransport(cfg, logger)
http.DefaultTransport = NewTransport(cfg, logger)
})
}

func newTransport(cfg config.ServiceConfig, logger logging.Logger) *http.Transport {
func NewTransport(cfg config.ServiceConfig, logger logging.Logger) *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Expand Down
10 changes: 5 additions & 5 deletions transport/http/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestRunServer_MTLS(t *testing.T) {
AllowInsecureConnections: false, // we do not check the server cert
CaCerts: []string{"ca.pem"},
ClientCerts: []config.ClientTLSCert{
config.ClientTLSCert{
{
Certificate: "cert.pem",
PrivateKey: "key.pem",
},
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestRunServer_MTLS(t *testing.T) {
// clientTLS config.
// This is a copy of the code we can find inside
// InitHTTPDefaultTransportWithLogger(serviceConfig, nil):
transport := newTransport(cfg, logger)
transport := NewTransport(cfg, logger)

defClient := http.Client{
Transport: transport,
Expand Down Expand Up @@ -459,7 +459,7 @@ func mtlsClient(certPath, keyPath string) (*http.Client, error) {
func h2cClient() *http.Client {
return &http.Client{
Transport: &http2.Transport{
DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
DialTLSContext: func(_ context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
},
AllowHTTP: true,
Expand Down Expand Up @@ -489,11 +489,11 @@ func TestRunServer_MultipleTLS(t *testing.T) {
TLS: &config.TLS{
CaCerts: []string{"ca.pem", "exampleca.pem"},
Keys: []config.TLSKeyPair{
config.TLSKeyPair{
{
PublicKey: "cert.pem",
PrivateKey: "key.pem",
},
config.TLSKeyPair{
{
PublicKey: "examplecert.pem",
PrivateKey: "examplekey.pem",
},
Expand Down

0 comments on commit f8a0bc2

Please sign in to comment.