Speculative fix for a panic that might arise during raft teardown (#18704)

This commit is contained in:
Nick Cabatoff 2023-01-16 13:49:11 -05:00 committed by GitHub
parent d5c35f39c3
commit b5f19fffe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

3
changelog/18704.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
storage/raft: Fix race with follower heartbeat tracker during teardown.
```

View File

@ -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 {