Skip to content

Commit eb47eb8

Browse files
Respoect max_inlight message count in reconnect
Previously if the message queue filled up for some reason like bad connection and the client disconnected (due to e.g. bad connection), it would send all of it's messages in _out_messages-queue and not respect _max_inflight_messages parameter. With some brokers and when we had 1000s of messages in queue and all being sent with qos 1 without any regard to the _max_inflight_messages, the broker would disconnect us or the connection would again break down. This patch makes sure _max_inflight_messages is respected when reconnect happens for any reason. I believe this also fixes #492 Signed-off-by: Juha Ylikoski <juha.ylikoski@treon.fi>
1 parent 9782ab8 commit eb47eb8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/paho/mqtt/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2945,16 +2945,18 @@ def _check_clean_session(self):
29452945
def _messages_reconnect_reset_out(self):
29462946
with self._out_message_mutex:
29472947
self._inflight_messages = 0
2948+
to_be_inflight = 0
29482949
for m in self._out_messages.values():
29492950
m.timestamp = 0
2950-
if self._max_inflight_messages == 0 or self._inflight_messages < self._max_inflight_messages:
2951+
if self._max_inflight_messages == 0 or to_be_inflight < self._max_inflight_messages:
29512952
if m.qos == 0:
29522953
m.state = mqtt_ms_publish
29532954
elif m.qos == 1:
29542955
# self._inflight_messages = self._inflight_messages + 1
29552956
if m.state == mqtt_ms_wait_for_puback:
29562957
m.dup = True
29572958
m.state = mqtt_ms_publish
2959+
to_be_inflight += 1
29582960
elif m.qos == 2:
29592961
# self._inflight_messages = self._inflight_messages + 1
29602962
if self._check_clean_session():
@@ -2968,6 +2970,7 @@ def _messages_reconnect_reset_out(self):
29682970
if m.state == mqtt_ms_wait_for_pubrec:
29692971
m.dup = True
29702972
m.state = mqtt_ms_publish
2973+
to_be_inflight += 1
29712974
else:
29722975
m.state = mqtt_ms_queued
29732976

0 commit comments

Comments
 (0)