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.
This commit is contained in:
Mahmood Ali
2020-05-26 09:35:55 -04:00
parent 4a7f4b22cf
commit 29eca948ad

View File

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