256dpi / arduino-mqtt

MQTT library for Arduino
MIT License
1.01k stars 232 forks source link

.publish hangs #239

Closed raphael-bmec-co closed 3 years ago

raphael-bmec-co commented 3 years ago

Hi thanks for the library.

I am seeing unexpected behaviour where .publish periodically does not return:

if (mqttClient_->publish(MQTT_STATUS_TOPIC_PREFIX + String(statusMessageIndex) + *macAddress_, state_json, false, 1)) {

I have seen this with several versions of the library up to the latest.

I am working on an ESP32 and have tried different versions of espressif/arduino-esp32 (1.0.4 AND 1.0.5).

I have tried setting the various timeouts and leaving them unset with the same results.

My code publishes a short message every 100ms.

Maybe you can help me understand if this is expected behaviour in some way and if so if there is a workaround to make it time out?

Also, I am not sure if it is related but I am seeing this crash pop up periodically:

assertion "pbuf_free: p->ref > 0" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/pbuf.c", line 766, function: pbuf_free
abort() was called at PC 0x40158047 on core 0
raphael-bmec-co commented 3 years ago

Solved.

Issue was related to multiple calls to the MQTT (publish and loop) from different threads. Prevented this with a mutex and the issue seems resolved at this time.