From 1075bc35da81bcb3de6d93a68374441c9eab597a Mon Sep 17 00:00:00 2001 From: HIMANSHU CHANDELA Date: Tue, 10 Nov 2026 03:49:59 +0530 Subject: [PATCH] common: fail RPC receive when the peer closes mid-payload SoapyRPCUnpacker::recv() reads the payload in a loop and only treats a negative recv() result as an error. When the server closes the connection after the header but before the whole payload has arrived, recv() keeps returning 0, bytesReceived never advances and the loop spins forever at full CPU, holding the device mutex. Every other call on that device then blocks as well. Throw a runtime_error when recv() returns 0, like the header receive already does, so the caller sees the dead link instead of hanging. --- common/SoapyRPCUnpacker.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/SoapyRPCUnpacker.cpp b/common/SoapyRPCUnpacker.cpp index 0ae74d5..2146dda 100644 --- a/common/SoapyRPCUnpacker.cpp +++ b/common/SoapyRPCUnpacker.cpp @@ -109,6 +109,12 @@ void SoapyRPCUnpacker::recv(void) { throw std::runtime_error("SoapyRPCUnpacker::recv(payload) FAIL: "+std::string(_sock.lastErrorMsg())); } + //recv() returns 0 when the peer has closed the connection, + //the rest of the payload will never arrive + if (ret == 0) + { + throw std::runtime_error("SoapyRPCUnpacker::recv(payload) FAIL: connection closed by peer"); + } bytesReceived += ret; }