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 } }