Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 203f48a

Browse files
authored
fix: extend locking in wsproxy to avoid race (and fix flake) (#14167)
1 parent b80d995 commit 203f48a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

enterprise/wsproxy/wsproxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func (s *Server) pingSiblingReplicas(replicas []codersdk.Replica) {
463463
errStr := pingSiblingReplicas(ctx, s.Logger, &s.replicaPingSingleflight, s.derpMeshTLSConfig, replicas)
464464
s.replicaErrMut.Lock()
465465
s.replicaErr = errStr
466-
s.replicaErrMut.Unlock()
466+
defer s.replicaErrMut.Unlock()
467467
if s.Options.ReplicaErrCallback != nil {
468468
s.Options.ReplicaErrCallback(replicas, s.replicaErr)
469469
}

enterprise/wsproxy/wsproxy_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ resourceLoop:
312312
t.Parallel()
313313

314314
// Try to connect to the DERP server on the no-derp-proxy region.
315-
client, err := derphttp.NewClient(key.NewNode(), proxyAPI3.Options.AccessURL.String(), func(format string, args ...any) {})
315+
client, err := derphttp.NewClient(key.NewNode(), proxyAPI3.Options.AccessURL.String(), func(string, ...any) {})
316316
require.NoError(t, err)
317317

318318
ctx := testutil.Context(t, testutil.WaitLong)
@@ -405,7 +405,7 @@ func TestDERPEndToEnd(t *testing.T) {
405405
proxyOnlyDERPMap.OmitDefaultRegions = true
406406
return true
407407
}, testutil.WaitLong, testutil.IntervalMedium)
408-
newDERPMapper := func(derpMap *tailcfg.DERPMap) *tailcfg.DERPMap {
408+
newDERPMapper := func(_ *tailcfg.DERPMap) *tailcfg.DERPMap {
409409
return proxyOnlyDERPMap
410410
}
411411
api.AGPL.DERPMapper.Store(&newDERPMapper)
@@ -577,7 +577,7 @@ func TestWorkspaceProxyDERPMeshProbe(t *testing.T) {
577577
registerBrokenProxy := func(ctx context.Context, t *testing.T, primaryAccessURL *url.URL, accessURL, token string) uuid.UUID {
578578
t.Helper()
579579
// Create a HTTP server that always replies with 500.
580-
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
580+
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
581581
rw.WriteHeader(http.StatusInternalServerError)
582582
}))
583583
t.Cleanup(srv.Close)
@@ -848,7 +848,7 @@ func TestWorkspaceProxyDERPMeshProbe(t *testing.T) {
848848
proxy := coderdenttest.NewWorkspaceProxyReplica(t, api, client, &coderdenttest.ProxyOptions{
849849
Name: "proxy-2",
850850
ProxyURL: proxyURL,
851-
ReplicaPingCallback: func(replicas []codersdk.Replica, err string) {
851+
ReplicaPingCallback: func(_ []codersdk.Replica, err string) {
852852
replicaPingErr <- err
853853
},
854854
})

0 commit comments

Comments
 (0)