From: Matt Corallo Date: Tue, 1 Feb 2022 22:33:02 +0000 (+0000) Subject: [Java] Close all sockets cleanly on `NioPeerHandler::interrupt` X-Git-Tag: v0.0.105.0~2^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=eab69282af298d16b07eaf3b7bdda07e184033cd;p=ldk-java [Java] Close all sockets cleanly on `NioPeerHandler::interrupt` --- diff --git a/src/main/java/org/ldk/batteries/NioPeerHandler.java b/src/main/java/org/ldk/batteries/NioPeerHandler.java index 2ab48d62..5963506f 100644 --- a/src/main/java/org/ldk/batteries/NioPeerHandler.java +++ b/src/main/java/org/ldk/batteries/NioPeerHandler.java @@ -332,10 +332,12 @@ public class NioPeerHandler { } /** - * Interrupt the background thread, stopping all peer handling. Disconnection events to the PeerHandler are not made, - * potentially leaving the PeerHandler in an inconsistent state. + * Interrupt the background thread, stopping all peer handling. + * + * After this method is called, the behavior of future calls to methods on this NioPeerHandler are undefined. */ public void interrupt() { + this.peer_manager.disconnect_all_peers(); shutdown = true; selector.wakeup(); try { @@ -347,6 +349,7 @@ public class NioPeerHandler { for (ServerSocketChannel chan : listening_sockets) { chan.close(); } + listening_sockets.clear(); } catch (IOException ignored) {} } Reference.reachabilityFence(this.peer_manager); // Almost certainly overkill, but no harm in it