mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 18:25:51 +00:00
Fix another stupid bug in the pinging code that could cause crashes.
This commit is contained in:
parent
e140662ea2
commit
3db55946df
@ -1114,7 +1114,7 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void complete() {
|
public void complete() {
|
||||||
Preconditions.checkNotNull(future, "Already completed");
|
checkNotNull(future, "Already completed");
|
||||||
Long elapsed = Utils.now().getTime() - startTimeMsec;
|
Long elapsed = Utils.now().getTime() - startTimeMsec;
|
||||||
Peer.this.addPingTimeData(elapsed);
|
Peer.this.addPingTimeData(elapsed);
|
||||||
log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed);
|
log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed);
|
||||||
@ -1197,18 +1197,16 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processPong(Pong m) {
|
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.
|
// Iterates over a snapshot of the list, so we can run unlocked here.
|
||||||
for (PendingPing pendingPing : pendingPings) {
|
for (PendingPing ping : pendingPings) {
|
||||||
ping = pendingPing;
|
|
||||||
if (m.getNonce() == ping.nonce) {
|
if (m.getNonce() == ping.nonce) {
|
||||||
pendingPings.remove(ping);
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -463,7 +463,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
assertEquals(elapsed, peer.getPingTime());
|
assertEquals(elapsed, peer.getPingTime());
|
||||||
// Do it again and make sure it affects the average.
|
// Do it again and make sure it affects the average.
|
||||||
future = peer.ping();
|
future = peer.ping();
|
||||||
outbound();
|
pingMsg = (Ping) outbound();
|
||||||
Utils.rollMockClock(50);
|
Utils.rollMockClock(50);
|
||||||
inbound(peer, new Pong(pingMsg.getNonce()));
|
inbound(peer, new Pong(pingMsg.getNonce()));
|
||||||
elapsed = future.get();
|
elapsed = future.get();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user