Skip to content

Commit

Permalink
add lock around saving ts clients
Browse files Browse the repository at this point in the history
Closes juanfont#1544

Co-Authored-By: Patrick Huang <[email protected]>
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby and PatrickHuang888 committed Sep 19, 2023
1 parent 4c12c02 commit 9ccf87c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions integration/embedded_derp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser(
)
}

s.mu.Lock()
user.Clients[tsClient.Hostname()] = tsClient
s.mu.Unlock()

return nil
})
Expand Down
8 changes: 5 additions & 3 deletions integration/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -326,7 +326,9 @@ func (s *Scenario) CreateTailscaleNodesInUser(
)
}

s.mu.Lock()
user.Clients[tsClient.Hostname()] = tsClient
s.mu.Unlock()

return nil
})
Expand Down

0 comments on commit 9ccf87c

Please sign in to comment.