From a828917152fb02e5e46db2b3c8d60c1aa1f00cf2 Mon Sep 17 00:00:00 2001 From: Fran Bull Date: Fri, 21 Feb 2025 11:24:00 -0800 Subject: [PATCH] allow concurrent usage of authorization --- tsconsensus/authorization.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tsconsensus/authorization.go b/tsconsensus/authorization.go index 67e685def..b815cbd15 100644 --- a/tsconsensus/authorization.go +++ b/tsconsensus/authorization.go @@ -4,6 +4,7 @@ import ( "context" "net/netip" "slices" + "sync" "tailscale.com/ipn/ipnstate" "tailscale.com/tsnet" @@ -13,6 +14,7 @@ type authorization struct { ts *tsnet.Server tag string peers *peers + mu sync.Mutex } func (a *authorization) refresh(ctx context.Context) error { @@ -24,19 +26,27 @@ func (a *authorization) refresh(ctx context.Context) error { if err != nil { return err } + a.mu.Lock() + defer a.mu.Unlock() a.peers = newPeers(tStatus) return nil } func (a *authorization) allowsHost(addr netip.Addr) bool { + a.mu.Lock() + defer a.mu.Unlock() return a.peers.peerExists(addr, a.tag) } func (a *authorization) selfAllowed() bool { + a.mu.Lock() + defer a.mu.Unlock() return a.peers.status.Self.Tags != nil && slices.Contains(a.peers.status.Self.Tags.AsSlice(), a.tag) } func (a *authorization) allowedPeers() []*ipnstate.PeerStatus { + a.mu.Lock() + defer a.mu.Unlock() if a.peers.allowedPeers == nil { return []*ipnstate.PeerStatus{} }