Skip to content

Commit eab6928

Browse files
committed
[Java] Close all sockets cleanly on NioPeerHandler::interrupt
1 parent ebef1f8 commit eab6928

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/ldk/batteries/NioPeerHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,12 @@ public void bind_listener(SocketAddress socket_address) throws IOException {
332332
}
333333

334334
/**
335-
* Interrupt the background thread, stopping all peer handling. Disconnection events to the PeerHandler are not made,
336-
* potentially leaving the PeerHandler in an inconsistent state.
335+
* Interrupt the background thread, stopping all peer handling.
336+
*
337+
* After this method is called, the behavior of future calls to methods on this NioPeerHandler are undefined.
337338
*/
338339
public void interrupt() {
340+
this.peer_manager.disconnect_all_peers();
339341
shutdown = true;
340342
selector.wakeup();
341343
try {
@@ -347,6 +349,7 @@ public void interrupt() {
347349
for (ServerSocketChannel chan : listening_sockets) {
348350
chan.close();
349351
}
352+
listening_sockets.clear();
350353
} catch (IOException ignored) {}
351354
}
352355
Reference.reachabilityFence(this.peer_manager); // Almost certainly overkill, but no harm in it

0 commit comments

Comments
 (0)