Bug in "paho-mqtt" crate

I'm developing an Mqtt client for an emdedded IoT application, and I'm using mqtt::AsyncClient.
I'm implemented my client following the guidelines of "legacy_async_subscribe.rs" in the examples of the distribution package. Everything works fine, but when the client tries to reconnect, because of a connection lost, it exit with some error. I tried with the original client in the example "legacy_async_subscribe.rs" connected to "test.mosuitto.org" and after several hours of connection I've got the following error, which resamples to the one reported in a previous converstion but is not the same:

Connected.
Connection lost. Attempting reconnect.
Connection attempt failed with error code -1.

Connection succeeded
Subscribing to topics: ["UAU/test/one", "UAU/hello/one"]
Connected.
legacy_async_subscribe(92357,0x16efdb000) malloc: Heap corruption detected, free list is damaged at 0x600000920020
*** Incorrect guard value: 141733920773
legacy_async_subscribe(92357,0x16efdb000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort cargo run --example legacy_async_subscribe -v

Attilio

This looks like it's probably Memory corruption after reconnect_with_callbacks · Issue #197 · eclipse/paho.mqtt.rust · GitHub so try downgrading to 0.11 and seeing if that fixes the issue until the upstream fix is released.


You might also want to try switching to the pure Rust rumqttc — Rust network library // Lib.rs which shouldn't have any of these memory safety issues.

Many thanks, I'm repeating the test with version 0.11.
I'll keep you informed about the result. It will take a while (hours or even a full day).
Attilio

I've tried V 0.11, but the bug is still there:

Compiling paho-mqtt v0.11.0 (/Users/attilio/Documents/RUST/paho.mqtt.rust)
Finished dev [unoptimized + debuginfo] target(s) in 1.98s
Running target/debug/examples/legacy_async_subscribe
Connecting to the MQTT server...
Connection succeeded
Subscribing to topics: ["UAU/test/one", "UAU/hello/one"]
Connected.
Connection lost. Attempting reconnect.
Connection attempt failed with error code -1.

Connection succeeded
Subscribing to topics: ["UAU/test/one", "UAU/hello/one"]
legacy_async_subscribe(83611,0x16f023000) malloc: *** error for object 0x600001144030: pointer being freed was not allocated
legacy_async_subscribe(83611,0x16f023000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort cargo run --example legacy_async_subscribe
attilio@Attilios-Mac-mini paho.mqtt.rust %

Author of the Paho Rust library here.

@simonbuchan got it right. There is a known bug when attempting to reconnect from within the on-disconnect callback. It's discussed in the GitHub Issues here:

I tracked it down to a problem in the underlying Paho C library, and reported it to them here:

As soon as the upstream bug is fixed, I'll release a new version of the Rust library.

It's probably better to discuss it in the GitHub issue so that it's all in one place.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.