mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-16 19:14:41 -07:00
Fix event ordering issue caused by re-locking
Noticed TestSystemAccountConnectionUpdatesStopAfterNoLocal failing du to the timer still being around. To avoid one event interfering with antoher, holding the account lock during send seems the most appropriate solution. sendInternalMsg essentially records the send queue and unlocks the server. This change just merges that with the code in sendAccConnsUpdate. Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
@@ -1159,8 +1159,13 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
|
||||
if !s.eventsEnabled() || a == nil {
|
||||
return
|
||||
}
|
||||
sendQ := s.sys.sendq
|
||||
if sendQ == nil {
|
||||
return
|
||||
}
|
||||
// Build event with account name and number of local clients and leafnodes.
|
||||
a.mu.RLock()
|
||||
a.mu.Lock()
|
||||
s.mu.Unlock()
|
||||
localConns := a.numLocalConnections()
|
||||
m := &AccountNumConns{
|
||||
Account: a.Name,
|
||||
@@ -1168,12 +1173,7 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
|
||||
LeafNodes: a.numLocalLeafNodes(),
|
||||
TotalConns: localConns + a.numLocalLeafNodes(),
|
||||
}
|
||||
a.mu.RUnlock()
|
||||
for _, sub := range subj {
|
||||
s.sendInternalMsg(sub, _EMPTY_, &m.Server, &m)
|
||||
}
|
||||
// Set timer to fire again unless we are at zero.
|
||||
a.mu.Lock()
|
||||
if localConns == 0 {
|
||||
clearTimer(&a.ctmr)
|
||||
} else {
|
||||
@@ -1184,7 +1184,11 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
|
||||
a.ctmr.Reset(eventsHBInterval)
|
||||
}
|
||||
}
|
||||
for _, sub := range subj {
|
||||
sendQ <- &pubMsg{nil, sub, _EMPTY_, &m.Server, &m, false}
|
||||
}
|
||||
a.mu.Unlock()
|
||||
s.mu.Lock()
|
||||
}
|
||||
|
||||
// accConnsUpdate is called whenever there is a change to the account's
|
||||
|
||||
Reference in New Issue
Block a user