Skip to content

Commit

Permalink
Fix panic in isGroupLeaderless
Browse files Browse the repository at this point in the history
Need to capture `rg.node` while the JetStream lock is held,
otherwise stopping an asset could race and it could be set
back to `nil`.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander authored and wallyqs committed Jan 9, 2025
1 parent adf8913 commit 3b6b9c8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,20 +940,21 @@ func (js *jetStream) isGroupLeaderless(rg *raftGroup) bool {
js.mu.RUnlock()
return false
}
node := rg.node
js.mu.RUnlock()
// If we don't have a leader.
if rg.node.GroupLeader() == _EMPTY_ {
if node.GroupLeader() == _EMPTY_ {
// Threshold for jetstream startup.
const startupThreshold = 10 * time.Second

if rg.node.HadPreviousLeader() {
if node.HadPreviousLeader() {
// Make sure we have been running long enough to intelligently determine this.
if time.Since(started) > startupThreshold {
return true
}
}
// Make sure we have been running for enough time.
if time.Since(rg.node.Created()) > lostQuorumIntervalDefault {
if time.Since(node.Created()) > lostQuorumIntervalDefault {
return true
}
}
Expand Down

0 comments on commit 3b6b9c8

Please sign in to comment.