Fix lock inversion.

This commit is contained in:
Mike Hearn 2012-12-24 23:33:13 +00:00
parent b71015a297
commit eb7c4be136

View File

@ -1098,17 +1098,19 @@ public class PeerGroup extends AbstractIdleService {
}
/** Given a list of Peers, return a Peer to be used as the download peer. */
protected Peer selectDownloadPeer(List<Peer> peers) {
synchronized (peers) {
if (peers.isEmpty())
return null;
// Make sure we don't select a peer that is behind/synchronizing itself.
int mostCommonChainHeight = getMostCommonChainHeight();
for (Peer peer : peers) {
if (peer.getBestHeight() == mostCommonChainHeight) return peer;
}
throw new IllegalStateException("Unreachable");
protected Peer selectDownloadPeer(List<Peer> origPeers) {
List<Peer> peers;
synchronized (origPeers) {
peers = new ArrayList<Peer>(origPeers);
}
if (peers.isEmpty())
return null;
// Make sure we don't select a peer that is behind/synchronizing itself.
int mostCommonChainHeight = getMostCommonChainHeight();
for (Peer peer : peers) {
if (peer.getBestHeight() == mostCommonChainHeight) return peer;
}
throw new IllegalStateException("Unreachable");
}
private static class PeerGroupThreadFactory implements ThreadFactory {