Skip to content

Commit

Permalink
Merge pull request #195 from xiangli-cmu/fix_remove_deadlock
Browse files Browse the repository at this point in the history
fix(server.go) fix potential deadlock when removing nodes
  • Loading branch information
xiang90 committed Mar 10, 2014
2 parents 3bc5b1b + 12e7a19 commit d660352
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,15 @@ func (s *server) RemovePeer(name string) error {

// Stop peer and remove it.
if s.State() == Leader {
peer.stopHeartbeat(true)
// We create a go routine here to avoid potential deadlock.
// We are holding log write lock when reach this line of code.
// Peer.stopHeartbeat can be blocked without go routine, if the
// target go routine (which we want to stop) is calling
// log.getEntriesAfter and waiting for log read lock.
// So we might be holding log lock and waiting for log lock,
// which lead to a deadlock.
// TODO(xiangli) refactor log lock
go peer.stopHeartbeat(true)
}

delete(s.peers, name)
Expand Down

0 comments on commit d660352

Please sign in to comment.