From 9ccf87c566ff73e1b5e78b80903d728381a4521c Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 10 Sep 2023 09:17:17 +0200 Subject: [PATCH] add lock around saving ts clients Closes #1544 Co-Authored-By: Patrick Huang Signed-off-by: Kristoffer Dalby --- integration/embedded_derp_test.go | 2 ++ integration/scenario.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/integration/embedded_derp_test.go b/integration/embedded_derp_test.go index 24bd898..669faf5 100644 --- a/integration/embedded_derp_test.go +++ b/integration/embedded_derp_test.go @@ -197,7 +197,9 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser( ) } + s.mu.Lock() user.Clients[tsClient.Hostname()] = tsClient + s.mu.Unlock() return nil }) diff --git a/integration/scenario.go b/integration/scenario.go index 6155f2d..a7e84ac 100644 --- a/integration/scenario.go +++ b/integration/scenario.go @@ -112,7 +112,7 @@ type Scenario struct { pool *dockertest.Pool network *dockertest.Network - headscaleLock sync.Mutex + mu sync.Mutex } // NewScenario creates a test Scenario which can be used to bootstraps a ControlServer with @@ -212,8 +212,8 @@ func (s *Scenario) Users() []string { // will be return, otherwise a new instance will be created. // TODO(kradalby): make port and headscale configurable, multiple instances support? func (s *Scenario) Headscale(opts ...hsic.Option) (ControlServer, error) { - s.headscaleLock.Lock() - defer s.headscaleLock.Unlock() + s.mu.Lock() + defer s.mu.Unlock() if headscale, ok := s.controlServers.Load("headscale"); ok { return headscale, nil @@ -326,7 +326,9 @@ func (s *Scenario) CreateTailscaleNodesInUser( ) } + s.mu.Lock() user.Clients[tsClient.Hostname()] = tsClient + s.mu.Unlock() return nil })