fix break in select

pull/820/head
Xiang Li 2013-07-07 16:52:18 -07:00
parent d3787f60c1
commit fa3ec69b6b
1 changed files with 10 additions and 6 deletions

View File

@ -483,6 +483,7 @@ func (s *Server) candidateLoop() {
// * Discover higher term: step down (§5.1)
votesGranted := 1
timeoutChan := afterBetween(s.ElectionTimeout(), s.ElectionTimeout()*2)
timeout := false
for {
// If we received enough votes then stop waiting for more votes.
@ -501,7 +502,6 @@ func (s *Server) candidateLoop() {
} else if resp.Term > s.currentTerm {
s.debugln("server.candidate.vote.failed")
s.setCurrentTerm(resp.Term, "", false)
break
}
case e := <-s.c:
@ -520,19 +520,23 @@ func (s *Server) candidateLoop() {
// Callback to event.
e.c <- err
// both process AER and RVR can make the server to follower
if s.State() == Follower {
break
}
case <-timeoutChan:
timeout = true
}
// both process AER and RVR can make the server to follower
// also break when timeout happens
if s.State() == Follower || timeout {
break
}
}
// break when we are not candidate
if s.State() != Candidate {
break
}
// continue when timeout happened
}
}