Exit raft removed checker if raft isn't initialized (#29329)

* check if not initialized

* add comment and fix flake
This commit is contained in:
miagilepner
2025-01-10 18:16:43 +01:00
committed by GitHub
parent 50509c6bab
commit dc0cd5af90
2 changed files with 16 additions and 0 deletions

View File

@@ -1479,6 +1479,19 @@ func (b *RaftBackend) StartRemovedChecker(ctx context.Context) {
for {
select {
case <-ticker.C:
// If the raft cluster has been torn down (which will happen on
// seal) the raft backend will be uninitialized. We want to exit
// the loop in that case. If the cluster unseals, we'll get a
// new backend setup and that will have its own removed checker.
// There is a ctx.Done() check below that will also exit, but
// in most (if not all) places we pass in context.Background()
// to this function. Checking initialization will prevent this
// loop from continuing to run after the raft backend is stopped
// regardless of the context.
if !b.Initialized() {
return
}
removed, err := b.IsNodeRemoved(ctx, b.localID)
if err != nil {
logger.Error("failed to check if node is removed", "node ID", b.localID, "error", err)

View File

@@ -364,6 +364,9 @@ func TestRaftHACluster_Removed_ReAdd(t *testing.T) {
if !server.Healthy {
return fmt.Errorf("server %s is unhealthy", serverID)
}
if server.NodeType != "voter" {
return fmt.Errorf("server %s has type %s", serverID, server.NodeType)
}
}
return nil
})