From 6b591d99f0dac61330b1ae5439284b62e00c00ff Mon Sep 17 00:00:00 2001 From: Marvin Mall Date: Tue, 9 Dec 2025 20:29:00 +0100 Subject: [PATCH] Fix: check for EOF when reading from socket Currently, we only check for EOF when reading in blocking mode. The client uses non-blocking reads most of the time though, such that we need to also check for EOF in those cases. --- src/MqttClient.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MqttClient.php b/src/MqttClient.php index 0ba1a84..5e801ce 100644 --- a/src/MqttClient.php +++ b/src/MqttClient.php @@ -1191,6 +1191,14 @@ protected function readFromSocketWithAutoReconnect(int $limit = self::SOCKET_REA */ protected function readFromSocket(int $limit = self::SOCKET_READ_BUFFER_SIZE, bool $withoutBlocking = false): string { + if (feof($this->socket)) { + $this->logger->error('The socket has been closed (by the broker) and reached EOF.'); + throw new DataTransferException( + DataTransferException::EXCEPTION_RX_DATA, + 'The socket has reached EOF which indicates it has been closed by the broker.' + ); + } + if ($withoutBlocking) { $result = fread($this->socket, $limit);