From 1890e7b297ee14b1766c6dc90425cb5c77e88d01 Mon Sep 17 00:00:00 2001 From: Daniel Albers Date: Fri, 10 Apr 2026 10:18:10 +0200 Subject: [PATCH] fix: PacketStreamFilter socket leak on abrupt disconnect This fix prevents TCP sockets from accumulating in CLOSE_WAIT following a network interruption. StreamInputShutdown ignored events that occurred while waiting for parts of a partially received packet. This could prevent the higher-level state machine from receiving the disconnect signal and closing the socket. The filter now correctly treats a stream closure during mid-packet reception as a protocol error, ensuring the disconnect event is propagated, and proceeds with the shutdown. --- src/lib/deskflow/PacketStreamFilter.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/deskflow/PacketStreamFilter.cpp b/src/lib/deskflow/PacketStreamFilter.cpp index 8ca1c7997..83a944290 100644 --- a/src/lib/deskflow/PacketStreamFilter.cpp +++ b/src/lib/deskflow/PacketStreamFilter.cpp @@ -164,7 +164,16 @@ void PacketStreamFilter::filterEvent(const Event &event) std::scoped_lock lock{m_mutex}; m_inputShutdown = true; if (m_size != 0) { - return; + if (m_buffer.getSize() >= m_size) { + // we have a complete packet, so we can process it before + // shutting down. + return; + } + // we have a partial packet, but the stream has shut down. + // we'll never get the rest of the packet, so we should + // signal an error and then shut down. + m_events->addEvent(Event(EventTypes::StreamInputFormatError, getEventTarget())); + m_size = 0; } }