Skip to content

Commit

Permalink
Respoect max_inlight message count in reconnect
Browse files Browse the repository at this point in the history
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 eclipse#492

Signed-off-by: Juha Ylikoski <juha.ylikoski@treon.fi>
  • Loading branch information
Juha-Ylikoski-Treon committed Dec 30, 2022
1 parent 9782ab8 commit eb47eb8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/paho/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,16 +2945,18 @@ def _check_clean_session(self):
def _messages_reconnect_reset_out(self):
with self._out_message_mutex:
self._inflight_messages = 0
to_be_inflight = 0
for m in self._out_messages.values():
m.timestamp = 0
if self._max_inflight_messages == 0 or self._inflight_messages < self._max_inflight_messages:
if self._max_inflight_messages == 0 or to_be_inflight < self._max_inflight_messages:
if m.qos == 0:
m.state = mqtt_ms_publish
elif m.qos == 1:
# self._inflight_messages = self._inflight_messages + 1
if m.state == mqtt_ms_wait_for_puback:
m.dup = True
m.state = mqtt_ms_publish
to_be_inflight += 1
elif m.qos == 2:
# self._inflight_messages = self._inflight_messages + 1
if self._check_clean_session():
Expand All @@ -2968,6 +2970,7 @@ def _messages_reconnect_reset_out(self):
if m.state == mqtt_ms_wait_for_pubrec:
m.dup = True
m.state = mqtt_ms_publish
to_be_inflight += 1
else:
m.state = mqtt_ms_queued

Expand Down

0 comments on commit eb47eb8

Please sign in to comment.