mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 13:59:09 +02:00
[management] Move service reload outside transaction in account settings update (#5325)
Bug Fixes Network and DNS updates now defer service and reverse-proxy reloads until after account updates complete, preventing inconsistent proxy state and race conditions. Chores Removed automatic peer/broadcast updates immediately following bulk service reloads. Tests Added a test ensuring network-range changes complete without deadlock.
This commit is contained in:
@@ -3918,3 +3918,36 @@ func TestAddNewUserToDomainAccountWithoutApproval(t *testing.T) {
|
||||
assert.False(t, user.PendingApproval, "User should not be pending approval")
|
||||
assert.Equal(t, existingAccountID, user.AccountID)
|
||||
}
|
||||
|
||||
// TestDefaultAccountManager_UpdateAccountSettings_NetworkRangeChange verifies that
|
||||
// changing NetworkRange via UpdateAccountSettings does not deadlock.
|
||||
// The deadlock occurs because ReloadAllServicesForAccount is called inside a DB
|
||||
// transaction but uses the main store connection, which blocks on the transaction lock.
|
||||
func TestDefaultAccountManager_UpdateAccountSettings_NetworkRangeChange(t *testing.T) {
|
||||
manager, _, err := createManager(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
accountID, err := manager.GetAccountIDByUserID(context.Background(), auth.UserAuth{UserId: userID})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Use a channel to detect if the call completes or hangs
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := manager.UpdateAccountSettings(ctx, accountID, userID, &types.Settings{
|
||||
PeerLoginExpiration: time.Hour,
|
||||
PeerLoginExpirationEnabled: true,
|
||||
NetworkRange: netip.MustParsePrefix("10.100.0.0/16"),
|
||||
Extra: &types.ExtraSettings{},
|
||||
})
|
||||
done <- err
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-done:
|
||||
require.NoError(t, err, "UpdateAccountSettings should complete without error")
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("UpdateAccountSettings deadlocked when changing NetworkRange")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user