eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.17k stars 723 forks source link

Respect max_inlight message count in reconnect #698

Open Juha-Ylikoski-Treon opened 1 year ago

Juha-Ylikoski-Treon commented 1 year ago

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

PierreF commented 8 months ago

Thanks for your contribution. I've written some test in https://github.com/eclipse/paho.mqtt.python/commit/a2574e61aea8ebb3bb5df3926f4b8771ca0afe8e (pushed on master) which show the problem exist on master.

It also show that there is another problem: message are published twice, once with mid=original_mid + N and once with mid=original_mid & dup = 1.

This issue still exists on this PR. I haven't yet looked whether the two issues are unrelated (and then the PR should be merged as-is) or they are related and should be fixed together.