PeerGroup: log exceptions in executor jobs, as the executor doesn't do this itself (gah)

This commit is contained in:
Mike Hearn
2014-12-08 22:10:39 +01:00
parent 0a34914d16
commit fef4829a3d

View File

@@ -413,6 +413,14 @@ public class PeerGroup implements TransactionBroadcaster {
@Override @Override
public void run() { public void run() {
try {
go();
} catch (Throwable e) {
log.error("Exception when trying to build connections", e); // The executor swallows exceptions :(
}
}
public void go() {
if (!vRunning) return; if (!vRunning) return;
boolean doDiscovery = false; boolean doDiscovery = false;
@@ -825,21 +833,25 @@ public class PeerGroup implements TransactionBroadcaster {
return executor.submit(new Runnable() { return executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
log.info("Starting ..."); try {
if (torClient != null) { log.info("Starting ...");
log.info("Starting Tor/Orchid ..."); if (torClient != null) {
torClient.start(); log.info("Starting Tor/Orchid ...");
try { torClient.start();
torClient.waitUntilReady(TOR_TIMEOUT_SECONDS * 1000); try {
} catch (Exception e) { torClient.waitUntilReady(TOR_TIMEOUT_SECONDS * 1000);
throw new RuntimeException(e); } catch (Exception e) {
throw new RuntimeException(e);
}
log.info("Tor ready");
} }
log.info("Tor ready"); channels.startAsync();
channels.awaitRunning();
triggerConnections();
setupPinging();
} catch (Throwable e) {
log.error("Exception when starting up", e); // The executor swallows exceptions :(
} }
channels.startAsync();
channels.awaitRunning();
triggerConnections();
setupPinging();
} }
}); });
} }
@@ -861,17 +873,21 @@ public class PeerGroup implements TransactionBroadcaster {
ListenableFuture future = executor.submit(new Runnable() { ListenableFuture future = executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
log.info("Stopping ..."); try {
// Blocking close of all sockets. log.info("Stopping ...");
channels.stopAsync(); // Blocking close of all sockets.
channels.awaitTerminated(); channels.stopAsync();
for (PeerDiscovery peerDiscovery : peerDiscoverers) { channels.awaitTerminated();
peerDiscovery.shutdown(); for (PeerDiscovery peerDiscovery : peerDiscoverers) {
peerDiscovery.shutdown();
}
if (torClient != null) {
torClient.stop();
}
vRunning = false;
} catch (Throwable e) {
log.error("Exception when shutting down", e); // The executor swallows exceptions :(
} }
if (torClient != null) {
torClient.stop();
}
vRunning = false;
} }
}); });
executor.shutdown(); executor.shutdown();
@@ -1017,6 +1033,14 @@ public class PeerGroup implements TransactionBroadcaster {
executor.execute(new Runnable() { executor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
go();
} catch (Throwable e) {
log.error("Exception when trying to recalculate Bloom filter", e); // The executor swallows exceptions :(
}
}
public void go() {
checkState(!lock.isHeldByCurrentThread()); checkState(!lock.isHeldByCurrentThread());
// Fully verifying mode doesn't use this optimization (it can't as it needs to see all transactions). // Fully verifying mode doesn't use this optimization (it can't as it needs to see all transactions).
if (chain != null && chain.shouldVerifyTransactions()) if (chain != null && chain.shouldVerifyTransactions())
@@ -1273,18 +1297,22 @@ public class PeerGroup implements TransactionBroadcaster {
vPingTask = executor.scheduleAtFixedRate(new Runnable() { vPingTask = executor.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
if (getPingIntervalMsec() <= 0) { try {
ListenableScheduledFuture<?> task = vPingTask; if (getPingIntervalMsec() <= 0) {
if (task != null) { ListenableScheduledFuture<?> task = vPingTask;
task.cancel(false); if (task != null) {
vPingTask = null; task.cancel(false);
vPingTask = null;
}
return; // Disabled.
} }
return; // Disabled. for (Peer peer : getConnectedPeers()) {
} if (peer.getPeerVersionMessage().clientVersion < Pong.MIN_PROTOCOL_VERSION)
for (Peer peer : getConnectedPeers()) { continue;
if (peer.getPeerVersionMessage().clientVersion < Pong.MIN_PROTOCOL_VERSION) peer.ping();
continue; }
peer.ping(); } catch (Throwable e) {
log.error("Exception in ping loop", e); // The executor swallows exceptions :(
} }
} }
}, getPingIntervalMsec(), getPingIntervalMsec(), TimeUnit.MILLISECONDS); }, getPingIntervalMsec(), getPingIntervalMsec(), TimeUnit.MILLISECONDS);