Skip to content

Commit 0106a95

Browse files
authored
lock account and use transaction (netbirdio#2767)
Signed-off-by: bcmmbaga <[email protected]>
1 parent 9929b22 commit 0106a95

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

management/server/account.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -2012,10 +2012,10 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st
20122012

20132013
jwtGroupsNames := extractJWTGroups(ctx, settings.JWTGroupsClaimName, claims)
20142014

2015-
unlockPeer := am.Store.AcquireWriteLockByUID(ctx, accountID)
2015+
unlockAccount := am.Store.AcquireWriteLockByUID(ctx, accountID)
20162016
defer func() {
2017-
if unlockPeer != nil {
2018-
unlockPeer()
2017+
if unlockAccount != nil {
2018+
unlockAccount()
20192019
}
20202020
}()
20212021

@@ -2024,12 +2024,12 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st
20242024
var hasChanges bool
20252025
var user *User
20262026
err = am.Store.ExecuteInTransaction(ctx, func(transaction Store) error {
2027-
user, err = am.Store.GetUserByUserID(ctx, LockingStrengthShare, claims.UserId)
2027+
user, err = transaction.GetUserByUserID(ctx, LockingStrengthShare, claims.UserId)
20282028
if err != nil {
20292029
return fmt.Errorf("error getting user: %w", err)
20302030
}
20312031

2032-
groups, err := am.Store.GetAccountGroups(ctx, accountID)
2032+
groups, err := transaction.GetAccountGroups(ctx, accountID)
20332033
if err != nil {
20342034
return fmt.Errorf("error getting account groups: %w", err)
20352035
}
@@ -2087,8 +2087,8 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st
20872087
return fmt.Errorf("error incrementing network serial: %w", err)
20882088
}
20892089
}
2090-
unlockPeer()
2091-
unlockPeer = nil
2090+
unlockAccount()
2091+
unlockAccount = nil
20922092

20932093
return nil
20942094
})

0 commit comments

Comments
 (0)