From 0bfd03091bbf7d1f0d2a1c653d97d696772f047c Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Sat, 16 Nov 2019 18:14:23 -0700 Subject: [PATCH] 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 --- server/norace_test.go | 14 ++++++++++++++ server/server.go | 1 + 2 files changed, 15 insertions(+) diff --git a/server/norace_test.go b/server/norace_test.go index 2aad8473..bcc68cd5 100644 --- a/server/norace_test.go +++ b/server/norace_test.go @@ -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) } diff --git a/server/server.go b/server/server.go index 424fc594..27e67584 100644 --- a/server/server.go +++ b/server/server.go @@ -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.