Skip to content

Commit

Permalink
Fix leaf connection missing LS+ sometimes (#4464)
Browse files Browse the repository at this point in the history
`TestNoRaceLeafNodeSmapUpdate` could occasionally fail with missing
`LS+` commands due not capturing all the inflight SUB commands as they
were being processed outside the client lock.
  • Loading branch information
wallyqs committed Aug 31, 2023
2 parents 2834142 + 9a9e84e commit 76c3942
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/leafnode.go
Expand Up @@ -1643,6 +1643,10 @@ func (s *Server) initLeafNodeSmapAndSendSubs(c *client) {
subs := _subs[:0]
ims := []string{}

// Hold the client lock otherwise there can be a race and miss some subs.
c.mu.Lock()
defer c.mu.Unlock()

acc.mu.RLock()
accName := acc.Name
accNTag := acc.nameTag
Expand Down Expand Up @@ -1718,7 +1722,6 @@ func (s *Server) initLeafNodeSmapAndSendSubs(c *client) {
}

// Now walk the results and add them to our smap
c.mu.Lock()
rc := c.leaf.remoteCluster
c.leaf.smap = make(map[string]int32)
for _, sub := range subs {
Expand Down Expand Up @@ -1784,7 +1787,6 @@ func (s *Server) initLeafNodeSmapAndSendSubs(c *client) {
c.mu.Unlock()
})
}
c.mu.Unlock()
}

// updateInterestForAccountOnGateway called from gateway code when processing RS+ and RS-.
Expand Down

0 comments on commit 76c3942

Please sign in to comment.