From 51e4b9aba613afa7a29c0196af126a5afcb92b74 Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Thu, 8 May 2025 14:19:47 +0200 Subject: [PATCH] remove write lock --- management/server/peer.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/management/server/peer.go b/management/server/peer.go index 049973f1b..ab8ab82fb 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -453,6 +453,7 @@ func (am *DefaultAccountManager) GetPeerNetwork(ctx context.Context, peerID stri // Each new Peer will be assigned a new next net.IP from the Account.Network and Account.Network.LastIP will be updated (IP's are not reused). // The peer property is just a placeholder for the Peer properties to pass further func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID string, peer *nbpeer.Peer) (*nbpeer.Peer, *types.NetworkMap, []*posture.Checks, error) { + startGlobal := time.Now() if setupKey == "" && userID == "" { // no auth method provided => reject access return nil, nil, nil, status.Errorf(status.Unauthenticated, "no peer auth method provided, please use a setup key or interactive SSO login") @@ -474,15 +475,6 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s return nil, nil, nil, status.Errorf(status.NotFound, "failed adding new peer: account not found") } - unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) - defer func() { - if unlock != nil { - unlock() - } - }() - - startGlobal := time.Now() - // This is a handling for the case when the same machine (with the same WireGuard pub key) tries to register twice. // Such case is possible when AddPeer function takes long time to finish after AcquireWriteLockByUID (e.g., database is slow) // and the peer disconnects with a timeout and tries to register again. @@ -685,9 +677,6 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s am.StoreEvent(ctx, opEvent.InitiatorID, opEvent.TargetID, opEvent.AccountID, opEvent.Activity, opEvent.Meta) - unlock() - unlock = nil - log.WithContext(ctx).Debugf("AddPeer took %v", time.Since(startGlobal)) if updateAccountPeers {