[mosquitto-2.0.18] mosquitto lib seems blocked when hasn't received PINGRESP
I'm using mosquitto lib 2.0.18 to implement my MQTT client. I met a issue like this:
My app forked 2 child processes as 2 MQTT clients. After running for 5 days, one of them seemed blocked and no messages any more.
From the log callback API, the last message is Client xxx sending PINGREQ
But there is no log Client xxx received PINGRESP following it.
After this, mosquitto_publish API was called but no any log printed and this API seemed not return.
This status will keep all the time, at least several days.
It seems blocked and no disconnected callback as well.
Without seeing a minimal reproduction of the issue, it's impossible to say for sure what might be happening. Could you share some code that illustrates what you are doing?
I added mosquitto_threaded_set(mosq, true) in my codes and this issue reproduced again with a little different actions.
As the first time, after running for several days, this issue happened. The log Client xxx sending PINGREQ was printed without a Client xxx received PINGRESP following it. mosquitto_publish API was called periodically in a work thread and it returned 0. But there is no publish callback called and those messages were not published successfully. There is no disconnected callback as well.
I configured mosquitto lib and started it by mosquitto_loop_forever. I created another thread as work thread, which publish messages periodically.
Attach a file to show some codes.
mqtt-client.c.txt
Could there by something happening in your callbacks that ends up blocking the thread?
Could there by something happening in your callbacks that ends up blocking the thread?
I don't think so. At the beginning of callbacks, there is always a log. But after Client xxx sending PINGREQ printed by mqtt_log_callback, there was no any log printed from callbacks. And work thread was still printing logs normally, so there was no block in the log print function. It means no callback was called after the last Client xxx sending PINGREQ.
void mqtt_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str)
{
/* Print all log messages regardless of level. */
log_trace("mqtt: %s", str);
}