Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove race warnings #739

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
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
Loading