From 0b1601542d698fc81f163d31d461eaf97004e554 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Mon, 19 Aug 2024 15:22:24 +0200 Subject: [PATCH] Wait for follower and leader loops to finish --- cluster/cluster.go | 4 ---- cluster/leader.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index 590b8c06..69551277 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -648,10 +648,6 @@ func (c *cluster) Shutdown() error { c.raft.Shutdown() } - // TODO: here might some situations, where the manager is still need from the synchronize loop and will run into a panic - c.manager = nil - c.raft = nil - return nil } diff --git a/cluster/leader.go b/cluster/leader.go index 60ab84d4..9d555f0e 100644 --- a/cluster/leader.go +++ b/cluster/leader.go @@ -180,6 +180,22 @@ func (c *cluster) monitorLeadership() { c.leaderLock.Unlock() } case <-c.shutdownCh: + if weAreFollowerCh != nil { + close(weAreFollowerCh) + } + + if weAreLeaderCh != nil { + close(weAreLeaderCh) + } + + if weAreEmergencyLeaderCh != nil { + close(weAreEmergencyLeaderCh) + } + + leaderLoop.Wait() + emergencyLeaderLoop.Wait() + followerLoop.Wait() + return } }