mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-15 10:40:41 -07:00
Clean tmp accounts map when race gets duplicate
Added check to the test to ensure that tmp map is empty. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -790,4 +790,18 @@ func TestNoRaceFetchAccountDoesNotRegisterAccountTwice(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("B should be able to receive messages")
|
||||
}
|
||||
|
||||
checkTmpAccounts := func(t *testing.T, s *Server) {
|
||||
t.Helper()
|
||||
empty := true
|
||||
s.tmpAccounts.Range(func(_, _ interface{}) bool {
|
||||
empty = false
|
||||
return false
|
||||
})
|
||||
if !empty {
|
||||
t.Fatalf("tmpAccounts is not empty")
|
||||
}
|
||||
}
|
||||
checkTmpAccounts(t, sa)
|
||||
checkTmpAccounts(t, sb)
|
||||
}
|
||||
|
||||
@@ -878,6 +878,7 @@ func (s *Server) registerAccountNoLock(acc *Account) *Account {
|
||||
// We are under the server lock. Lookup from map, if present
|
||||
// return existing account.
|
||||
if a, _ := s.accounts.Load(acc.Name); a != nil {
|
||||
s.tmpAccounts.Delete(acc.Name)
|
||||
return a.(*Account)
|
||||
}
|
||||
// Finish account setup and store.
|
||||
|
||||
Reference in New Issue
Block a user