Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
fix(server): release the server lock while stopping peers
Browse files Browse the repository at this point in the history
Avoid a deadlock situation:

- Server is changing the term via setCurrentTerm() which also holds
  the server.Lock

- Peer is in the flush() routine and attempts to takes the server.Lock
  via p.server.Term() in sendAppendEntriesRequest()

The peer cannot take the lock because it is held by the server. The
server is waiting for the peer to shut down. Progress stops.
  • Loading branch information
xiang90 authored and Brandon Philips committed Feb 7, 2014
1 parent e615676 commit 78ce625
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server.go
Expand Up @@ -500,9 +500,11 @@ func (s *server) setCurrentTerm(term uint64, leaderName string, append bool) {
if term > s.currentTerm {
// stop heartbeats before step-down
if s.state == Leader {
s.mutex.Unlock()
for _, peer := range s.peers {
peer.stopHeartbeat(false)
}
s.mutex.Lock()
}
// update the term and clear vote for
s.state = Follower
Expand Down

0 comments on commit 78ce625

Please sign in to comment.