From c9ce5b421790335e547dbfc96ccf7f30f0eeaff3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 1 Jul 2013 22:51:17 -0700 Subject: [PATCH] when promoted, election timeout should be stopped --- server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 3dc0f48df6b..3c9f9e737f2 100644 --- a/server.go +++ b/server.go @@ -96,6 +96,7 @@ func NewServer(name string, path string, transporter Transporter, stateMachine S state: Stopped, peers: make(map[string]*Peer), log: NewLog(), + stepDown: make(chan uint64), electionTimer: NewTimer(DefaultElectionTimeout, DefaultElectionTimeout*2), heartbeatTimeout: DefaultHeartbeatTimeout, } @@ -644,7 +645,6 @@ func (s *Server) promote() (bool, error) { continue } - // must be stepdown return false, fmt.Errorf("raft.Server: Term changed during election, stepping down: (%v > %v)", s.currentTerm, term) // TODO: is this still needed? @@ -830,7 +830,7 @@ func (s *Server) electionTimeout() { // TODO race condition with unload if s.electionTimer.Start() { - s.promote() + go s.promote() return } else {