From ab9ed3945a80b93e294bc6927f0d27a421f0bb19 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 078b438a0d2..26e7f97f25f 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 {