From 1d6eaa59a71639b2856c4fa928d2460d83e3bc25 Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Tue, 30 Jul 2024 15:46:07 +0100 Subject: [PATCH] Fix race condition when recreating subs Signed-off-by: Neil Twigg --- server/raft.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/raft.go b/server/raft.go index f60af86ccf7..4f5956889e4 100644 --- a/server/raft.go +++ b/server/raft.go @@ -553,8 +553,14 @@ func (n *raft) recreateInternalSubsLocked() error { acc := n.s.accountNRGAllowed.Load() if acc { // Check whether the specific account has account NRG enabled. - if a, _ := n.s.lookupAccount(n.accName); a != nil && a.js != nil { - acc = a.js.accountNRG.Load() + if a, _ := n.s.lookupAccount(n.accName); a != nil { + a.mu.RLock() + ajs := a.js + a.mu.RUnlock() + // Check whether the specific account has JetStream enabled. + if ajs != nil { + acc = ajs.accountNRG.Load() + } } } if acc {