3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Move ping timer cancellation to after channel close during PeerGroup shutdown.

Check if the service is running before trying to re-ping a peer.
Attempts to solve a shutdown race. Updates issue 275.
This commit is contained in:
Mike Hearn 2013-01-12 13:52:24 +01:00
parent 89c611d86b
commit 9a65d4cab8

View File

@ -486,9 +486,6 @@ public class PeerGroup extends AbstractIdleService {
@Override
protected void shutDown() throws Exception {
// This is run on a separate thread by the AbstractIdleService implementation.
synchronized (this) {
pingTimer.cancel();
}
// Blocking close of all sockets. TODO: there is a race condition here, for the solution see:
// http://biasedbit.com/netty-releaseexternalresources-hangs/
channels.close().await();
@ -497,6 +494,9 @@ public class PeerGroup extends AbstractIdleService {
for (PeerDiscovery peerDiscovery : peerDiscoverers) {
peerDiscovery.shutdown();
}
synchronized (this) {
pingTimer.cancel();
}
}
/**
@ -715,7 +715,7 @@ public class PeerGroup extends AbstractIdleService {
@Override
public void run() {
try {
if (!peers.contains(peer))
if (!peers.contains(peer) || !PeerGroup.this.isRunning())
return; // Peer was removed/shut down.
peer.ping().addListener(this, MoreExecutors.sameThreadExecutor());
} catch (Exception e) {