From 7cfa0f7786cbcb07df42063a95ba0e62eec8f07a Mon Sep 17 00:00:00 2001 From: Kognition QA Date: Sat, 7 Mar 2026 09:09:31 -0500 Subject: [PATCH] fix: clean up dead client connections on SocketException in NioReceiver reader loop When a client connection resets (Connection reset SocketException), the IOException was caught by the outer reader loop but the broken channel and selector key were never cleaned up. Over time, dead keys accumulate in the selector, firing readable events every cycle, causing a busy spin that starves the reader thread and effectively stops the service from processing new messages. Fix: catch IOException at the individual Client.read() call site and invoke closeup() to properly cancel the key and close the channel, matching the cleanup behavior already used for EOF and corrupt messages. --- .../java/net/dempsy/transport/tcp/nio/NioReceiver.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dempsy-framework.impl/src/main/java/net/dempsy/transport/tcp/nio/NioReceiver.java b/dempsy-framework.impl/src/main/java/net/dempsy/transport/tcp/nio/NioReceiver.java index 7389442a..8386c18e 100644 --- a/dempsy-framework.impl/src/main/java/net/dempsy/transport/tcp/nio/NioReceiver.java +++ b/dempsy-framework.impl/src/main/java/net/dempsy/transport/tcp/nio/NioReceiver.java @@ -479,7 +479,12 @@ public void run() { continue; if(key.isReadable()) { - ((Client)key.attachment()).read(key); + try { + ((Client)key.attachment()).read(key); + } catch(final IOException cioe) { + LOGGER.warn(thisNode + " connection reset from client, closing: " + cioe.getMessage()); + ((Client)key.attachment()).closeup((SocketChannel)key.channel(), key); + } } else // this shouldn't be possible LOGGER.info(thisNode + " reciever got an unexpexted selection key " + key); }