From dc0cd5af9058fac93009ed3e369d34be6feb4ce4 Mon Sep 17 00:00:00 2001 From: miagilepner Date: Fri, 10 Jan 2025 18:16:43 +0100 Subject: [PATCH] Exit raft removed checker if raft isn't initialized (#29329) * check if not initialized * add comment and fix flake --- physical/raft/raft.go | 13 +++++++++++++ vault/external_tests/raftha/raft_ha_test.go | 3 +++ 2 files changed, 16 insertions(+) diff --git a/physical/raft/raft.go b/physical/raft/raft.go index b68cc852ef..a667830c6c 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -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) diff --git a/vault/external_tests/raftha/raft_ha_test.go b/vault/external_tests/raftha/raft_ha_test.go index bd16356615..705712d9ad 100644 --- a/vault/external_tests/raftha/raft_ha_test.go +++ b/vault/external_tests/raftha/raft_ha_test.go @@ -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 })