From 731607f055127e377e6bcbb9671fbec36a6d1a4e Mon Sep 17 00:00:00 2001 From: James Parrott <80779630+JamesParrott@users.noreply.github.com> Date: Mon, 15 Jun 2026 12:52:49 +0100 Subject: [PATCH] Re-ping if we are downloading Don't disconnect. Send multiple pings during large downloads. Only disconn if _last_mg_in outside keep alive Don't close socket if _last_mg_in was within keep alive (don't rely on _ping_t only) Send out pingreq, do not disconnect, if downloading, or pingreq overdue. REvert loop misc but make it only disconnect on _last_msg_in, not _ping_t Run workflows on this branch This branch, not the other Disconnect if no ping response, but if downloading ping again, resetting _ping_t Run workflows on this branch Only re-ping if we are downloading --- src/paho/mqtt/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index db1270d4..43bc291a 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -2174,6 +2174,8 @@ def loop_misc(self) -> MQTTErrorCode: return MQTTErrorCode.MQTT_ERR_SUCCESS + + def max_inflight_messages_set(self, inflight: int) -> None: """Set the maximum number of messages with QoS>0 that can be part way through their network flow at once. Defaults to 20.""" @@ -3274,7 +3276,7 @@ def _check_keepalive(self) -> None: last_msg_in = self._last_msg_in if self._sock is not None and (now - last_msg_out >= self._keepalive or now - last_msg_in >= self._keepalive): - if self._state == _ConnectionState.MQTT_CS_CONNECTED and self._ping_t == 0: + if self._state == _ConnectionState.MQTT_CS_CONNECTED and (self._ping_t == 0 or now - last_msg_in < self.keepalive): try: self._send_pingreq() except Exception: