diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java index 48e4282e..db361207 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelClientStates.java @@ -207,10 +207,16 @@ public class StoredPaymentChannelClientStates implements WalletExtension { channelTimeoutHandler.schedule(new TimerTask() { @Override public void run() { - TransactionBroadcaster announcePeerGroup = getAnnouncePeerGroup(); - removeChannel(channel); - announcePeerGroup.broadcastTransaction(channel.contract); - announcePeerGroup.broadcastTransaction(channel.refund); + try { + TransactionBroadcaster announcePeerGroup = getAnnouncePeerGroup(); + removeChannel(channel); + announcePeerGroup.broadcastTransaction(channel.contract); + announcePeerGroup.broadcastTransaction(channel.refund); + } catch (Exception e) { + // Something went wrong closing the channel - we catch + // here or else we take down the whole Timer. + log.error("Auto-closing channel failed", e); + } } // Add the difference between real time and Utils.now() so that test-cases can use a mock clock. }, new Date(channel.expiryTimeSeconds() * 1000 + (System.currentTimeMillis() - Utils.currentTimeMillis()))); diff --git a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java index 8fd1cdff..af8c3265 100644 --- a/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java +++ b/core/src/main/java/org/bitcoinj/protocols/channels/StoredPaymentChannelServerStates.java @@ -190,7 +190,13 @@ public class StoredPaymentChannelServerStates implements WalletExtension { @Override public void run() { log.info("Auto-closing channel: {}", channel); - closeChannel(channel); + try { + closeChannel(channel); + } catch (Exception e) { + // Something went wrong closing the channel - we catch + // here or else we take down the whole Timer. + log.error("Auto-closing channel failed", e); + } } }, autocloseTime); } finally {