LiamBindle / MQTT-C

A portable MQTT C client for embedded systems and PCs alike.
https://liambindle.ca/MQTT-C
MIT License
766 stars 269 forks source link

Reset client->send_offset on reinit #179

Open MartinKlang opened 1 year ago

MartinKlang commented 1 year ago

This PR fixes a bug that can cause problems when calling mqtt_reinit(), for example from the reconnect callback.

If the connection is re-established while sending multi-part messages then MQTT-C will send garbage data from an old offset into the re-initialised message queue. Ultimately leading to junk being sent to the host.

This behaviour has been observed in the wild on devices with intermittent network connections.

MartinKlang commented 1 year ago

I don't know why the CI fails, could it be an intermittent problem? It passes locally:

[MQTT-C API Tests]
[==========] Running 3 test(s).
[ RUN      ] TEST__api__connect_ping_disconnect
[       OK ] TEST__api__connect_ping_disconnect
[ RUN      ] TEST__api__publish_subscribe__single
[       OK ] TEST__api__publish_subscribe__single
[ RUN      ] TEST__api__publish_subscribe__multiple
[       OK ] TEST__api__publish_subscribe__multiple
[==========] 3 test(s) run.
[  PASSED  ] 3 test(s).