From 29eca948ad6a863300b1dd0cb93ea8b9f7b49df7 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 26 May 2020 09:35:55 -0400 Subject: [PATCH] terminate leader goroutines on shutdown Ensure that nomad steps down (and terminate leader goroutines) on shutdown, when the server is the leader. Without this change, `monitorLeadership` may handle `shutdownCh` event and exit early before handling the raft `leaderCh` event and end up leaking leadership goroutines. --- nomad/leader.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nomad/leader.go b/nomad/leader.go index 18c36ef38..0822c4e05 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -108,6 +108,9 @@ func (s *Server) monitorLeadership() { s.logger.Warn("cluster leadership gained and lost leadership immediately. Could indicate network issues, memory paging, or high CPU load.") } case <-s.shutdownCh: + if weAreLeaderCh != nil { + leaderStep(false) + } return } }