3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 23:03:04 +00:00

Fix another stupid bug in the pinging code that could cause crashes.

This commit is contained in:
Mike Hearn 2013-03-15 16:00:05 +01:00
parent e140662ea2
commit 3db55946df
2 changed files with 7 additions and 9 deletions

View File

@ -1114,7 +1114,7 @@ public class Peer {
}
public void complete() {
Preconditions.checkNotNull(future, "Already completed");
checkNotNull(future, "Already completed");
Long elapsed = Utils.now().getTime() - startTimeMsec;
Peer.this.addPingTimeData(elapsed);
log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed);
@ -1197,18 +1197,16 @@ public class Peer {
}
private void processPong(Pong m) {
PendingPing ping = null;
log.info("{}: pong! {}", this, m.getNonce());
// Iterates over a snapshot of the list, so we can run unlocked here.
for (PendingPing pendingPing : pendingPings) {
ping = pendingPing;
for (PendingPing ping : pendingPings) {
if (m.getNonce() == ping.nonce) {
pendingPings.remove(ping);
break;
// This line may trigger an event listener that re-runs ping().
ping.complete();
return;
}
}
// 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.
if (ping != null) ping.complete();
}
/**

View File

@ -463,7 +463,7 @@ public class PeerTest extends TestWithNetworkConnections {
assertEquals(elapsed, peer.getPingTime());
// Do it again and make sure it affects the average.
future = peer.ping();
outbound();
pingMsg = (Ping) outbound();
Utils.rollMockClock(50);
inbound(peer, new Pong(pingMsg.getNonce()));
elapsed = future.get();