callbacks(3)
β¨ NAME β¨
callbacks β Callbacks π
okay bestie, this one's from the Library Functions Manual, it's callbacks(3), and it is so important that you actually read it, because the vibes here are "if you do this wrong your program just freezes forever and stares at you." π«
π¨ the one rule, and it's giving main character energy
You must not call a function from this API from within a callback, otherwise a deadlock might result. Like, not even a little. Not even a quick one. Nope. π
The only exception to this is the ability to call connect within the connection lost callback, to allow a reconnect. That's it, that's the whole guest list. ποΈ
When you're using MQTT 5.0, you can also call connect from within the disconnected callback β which is the one that gets invoked when the MQTT server sends a disconnect packet. This server behaviour is allowed in MQTT 5.0, but not in MQTT 3.1.1, so the disconnected callback will never be invoked if you use MQTT 3.1.1. Periodt. π
ββοΈ
In particular β and I need you to hear me on this one β you must not make a publish call within the message arrived callback. π«
π‘ good news tho: these restrictions are all lifted in the MQTTAsync API. if you want to do whatever you want inside your callbacks, that's your girl. β¨
πΈ about callbacks you never assigned
If no callbacks are assigned, this will include the message arrived callback. That's lowkey fine and totally valid β it could be done if the application is a pure publisher, and does not subscribe to any topics. Slay, honestly. π
If however messages are received, and no message arrived callback is set, or receive not called, then those messages will accumulate and take up memory, as there is no place for them to be delivered. It is up to the application to protect against this situation. π§ π₯
π fr fr, that's a memory leak with extra steps. the library is not gonna babysit you here β that's on you, bestie.
okay that's the whole page, you ate it, go build something iconic π
this has been the Paho MQTT C Client Library, dated Tue Jun 2 2026 00:00:00 β take care of yourself and your callbacks π¦π
π¦ where this page comes from
- fedora 44: paho-c-devel 1.3.16-1.fc44 Β· BSD-3-Clause AND EPL-2.0
- fedora 44: paho-c-devel 1.3.16-1.fc44 Β· BSD-3-Clause AND EPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms