From eab69282af298d16b07eaf3b7bdda07e184033cd Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 1 Feb 2022 22:33:02 +0000 Subject: [PATCH] [Java] Close all sockets cleanly on `NioPeerHandler::interrupt` --- src/main/java/org/ldk/batteries/NioPeerHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 -- 2.39.5