From 2ae342b1b7a2af38332c3d41e9b9e8afa93249f0 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Mon, 16 Jan 2023 13:49:11 -0500 Subject: [PATCH] Speculative fix for a panic that might arise during raft teardown (#18704) --- changelog/18704.txt | 3 +++ physical/raft/raft_autopilot.go | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 changelog/18704.txt diff --git a/changelog/18704.txt b/changelog/18704.txt new file mode 100644 index 000000000000..bc76db9ba923 --- /dev/null +++ b/changelog/18704.txt @@ -0,0 +1,3 @@ +```release-note:bug +storage/raft: Fix race with follower heartbeat tracker during teardown. +``` \ No newline at end of file diff --git a/physical/raft/raft_autopilot.go b/physical/raft/raft_autopilot.go index 5596bbf4255f..1c000dc04824 100644 --- a/physical/raft/raft_autopilot.go +++ b/physical/raft/raft_autopilot.go @@ -551,6 +551,13 @@ func (b *RaftBackend) startFollowerHeartbeatTracker() { } for range tickerCh { b.l.RLock() + if b.raft == nil { + // We could be racing with teardown, which will stop the ticker + // but that doesn't guarantee that we won't reach this line with a nil + // b.raft. + b.l.RUnlock() + return + } b.followerStates.l.RLock() myAppliedIndex := b.raft.AppliedIndex() for peerID, state := range b.followerStates.followers {