From 938ffcba20b791566b929f3154710716ae2ae601 Mon Sep 17 00:00:00 2001 From: Waldemar Quevedo Date: Tue, 2 May 2023 17:36:08 -0700 Subject: [PATCH] Fix race in reload and gateway sublist check Signed-off-by: Waldemar Quevedo --- server/gateway.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/gateway.go b/server/gateway.go index 35b50a1264..7907b01488 100644 --- a/server/gateway.go +++ b/server/gateway.go @@ -2680,12 +2680,11 @@ func (s *Server) gatewayHandleSubjectNoInterest(c *client, acc *Account, accName // If there is no subscription for this account, we would normally // send an A-, however, if this account has the internal subscription // for service reply, send a specific RS- for the subject instead. - hasSubs := acc.sl.Count() > 0 - if !hasSubs { - acc.mu.RLock() - hasSubs = acc.siReply != nil - acc.mu.RUnlock() - } + // Need to grab the lock here since sublist can change during reload. + acc.mu.RLock() + hasSubs := acc.sl.Count() > 0 || acc.siReply != nil + acc.mu.RUnlock() + // If there is at least a subscription, possibly send RS- if hasSubs { sendProto := false