goraft/raft — pull request #175 by philips (2014-02-07 18:33:08+00:00)
Title: Cleanup locks in peer

This is identical to #169 but cleans up the commit messages with feedback from Xiang and a quick refactor.

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.