Skip to content

Commit

Permalink
Merge #61868
Browse files Browse the repository at this point in the history
61868: testutils: fix a nil pointer panic in TestCluster.GetRaftLeader r=lunevalex a=lunevalex

Fixes #61485

TestReplicateRemovedNodeDisruptiveElection exposed a nil pointer panic
in TestCluster.GetRaftLeader. Replica.RaftStatus could return nil
if the raft group is not yet initilized. This commit adds a guard for
that condition.

Release note: None

Co-authored-by: Alex Lunev <[email protected]>
  • Loading branch information
craig[bot] and lunevalex committed Mar 11, 2021
2 parents 5e4e48f + c23edf3 commit 38d3138
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/testutils/testcluster/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,9 @@ func (tc *TestCluster) GetRaftLeader(t testing.TB, key roachpb.RKey) *kvserver.R
return nil
}
raftStatus := repl.RaftStatus()
if raftStatus == nil {
return errors.Errorf("raft group is not initialized for replica with key %s", key)
}
if raftStatus.Term > latestTerm || (raftLeaderRepl == nil && raftStatus.Term == latestTerm) {
// If we find any newer term, it means any previous election is
// invalid.
Expand Down

0 comments on commit 38d3138

Please sign in to comment.