Skip to content

Commit

Permalink
consul: Clear peer set on leave. Fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Apr 23, 2014
1 parent b8d185a commit b4ae24d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Server struct {
// strong consistency.
fsm *consulFSM

// Have we attempted to leave the cluster
left bool

// Logger uses the provided LogOutput
logger *log.Logger

Expand Down Expand Up @@ -364,6 +367,12 @@ func (s *Server) Shutdown() error {
s.logger.Printf("[WARN] consul: Error shutting down raft: %s", err)
}
s.raftStore.Close()

// Clear the peer set on a graceful leave to avoid
// triggering elections on a rejoin.
if s.left {
s.raftPeers.SetPeers(nil)
}
}

if s.rpcListener != nil {
Expand Down Expand Up @@ -391,6 +400,7 @@ func (s *Server) Shutdown() error {
// Leave is used to prepare for a graceful shutdown of the server
func (s *Server) Leave() error {
s.logger.Printf("[INFO] consul: server starting leave")
s.left = true

// Leave the WAN pool
if s.serfWAN != nil {
Expand Down Expand Up @@ -434,7 +444,8 @@ func (s *Server) Leave() error {
// Wait for the commit
select {
case err := <-ch:
if err != nil {
// Ignore if we have already been deregistered by the leader
if err != nil && err.Error() != raft.UnknownPeer.Error() {
s.logger.Printf("[ERR] consul: failed to leave Raft cluster: %v", err)
}
case <-time.After(3 * time.Second):
Expand Down

0 comments on commit b4ae24d

Please sign in to comment.