From 849f74336a6aec355e7d1b619c4a6fa89463b748 Mon Sep 17 00:00:00 2001 From: Hmvp Date: Tue, 16 Sep 2014 10:34:24 +0200 Subject: [PATCH] Remove message from inflight when not connected Publishes with qos > 0 which are sent before a CONACK is received are still counted as inflight even though they don't really get sent. This means they get sent after the retry period (20 sec default) But this won't work when max_inflight is 1 since this means no retry will get sent and we wait untill keepalive is exhausted This then forces a reconnect and will reset stuff so messages can be sent. Change-Id: I516a6cce8e5bbfbd3030711a80044af4e5bf6733 Signed-off-by: Hmvp --- src/paho/mqtt/client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index b46dc1e..75de425 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -909,6 +909,16 @@ class Client(object): self._out_message_mutex.release() rc = self._send_publish(message.mid, message.topic, message.payload, message.qos, message.retain, message.dup) + + # remove from inflight messages so it will be send after a connection is made + if rc is MQTT_ERR_NO_CONN: + with self._out_message_mutex: + self._inflight_messages -= 1 + if qos == 1: + message.state = mqtt_ms_publish_qos1 + elif qos == 2: + message.state = mqtt_ms_publish_qos2 + return (rc, local_mid) else: message.state = mqtt_ms_queued; -- 2.39.5