3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 02:35:52 +00:00

Don't hold the Peer lock whilst invoking a ping callback.

This commit is contained in:
Mike Hearn 2012-12-24 23:47:14 +00:00
parent eb7c4be136
commit ffc953abc8

View File

@ -846,9 +846,10 @@ public class Peer {
return (long)((double) sum / lastPingTimes.length); return (long)((double) sum / lastPingTimes.length);
} }
private synchronized void processPong(Pong m) { private void processPong(Pong m) {
ListIterator<PendingPing> it = pendingPings.listIterator();
PendingPing ping = null; PendingPing ping = null;
synchronized (this) {
ListIterator<PendingPing> it = pendingPings.listIterator();
while (it.hasNext()) { while (it.hasNext()) {
ping = it.next(); ping = it.next();
if (m.getNonce() == ping.nonce) { if (m.getNonce() == ping.nonce) {
@ -856,6 +857,7 @@ public class Peer {
break; break;
} }
} }
}
// This line may trigger an event listener being run on the same thread, if one is attached to the // This line may trigger an event listener being run on the same thread, if one is attached to the
// pending ping future. That event listener may in turn re-run ping, so we need to do it last. // pending ping future. That event listener may in turn re-run ping, so we need to do it last.
if (ping != null) ping.complete(); if (ping != null) ping.complete();