This critical section is a bit confusing with the Unlock being straddled over the else statement. Perhaps this might be better:

```
snapShotNeeded := true
server.log.mutex.Lock()
if prevLogIndex >= server.log.StartIndex() {
  req := server.createAppendEntriesRequest(prevLogIndex)
  snapShotNeeded = false
}
server.log.mutex.Unlock()

p.mutex.Lock()
if snapShotNeeded {
  p.sendSnapshotRequest(req)
} else {
  p.sendFlushRequest(req)
}
p.mutex.Unlock()
```