fix break in select
parent
d3787f60c1
commit
fa3ec69b6b
16
server.go
16
server.go
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue