From 9a9e84ea5c8588bd5a09f39e7d1698d896d9b249 Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Thu, 31 Aug 2023 10:00:15 -0700 Subject: [PATCH] Fix leaf connection missing LS+ sometimes Signed-off-by: Waldemar Quevedo --- server/leafnode.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/leafnode.go b/server/leafnode.go index 39170e3c17..9b78676a79 100644 --- a/server/leafnode.go +++ b/server/leafnode.go @@ -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 @@ -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 { @@ -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-.