-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reconnect callback related issues #111
Comments
Try to clear the queue after mqtt_sync () After calling mqtt_publish (), check that the error is MQTT_ERROR_SEND_BUFFER_IS_FULL. If so, change to MQTT_OK. |
@przemyslawzygmunt thank you. |
This should be handled by the library but is not. In my opinion, the library needs to be rebuilt not only in this area. Perhaps it is worth starting work on a new version that will not necessarily be compatible with the previous one.
|
Hello, I used mqtt in a project and encountered some problems:
|
@Pluto-kk Please show your code. |
Hi @yamt thanks for writing. Sorry for no responding earlier.
This is challenging because a design contraint of MQTT-C is no malloc. Therefore, the send/receive buffers that you initialize the client with is the only block of memory (excluding stack) that MQTT-C uses. You can recover from this event if you're only dealing with QoS 0, but I don't think it's possible for QoS 2 (since behind-the-scenes, the client must enqueue the PUBREL message immediately). The fatal error is specifically the QoS 2 case, so there is room for improvement. I think there's potentially some room fro improvement in freeing up space in the message queue (freeing messages past the first unacked message in the queue). The error handling here isn't trivial, but I'd be happy to merge a safe PR that improves on it.
This is true. You can loop inside of your reconnect call back though, until you can re-establish the connection. Again, this is an area has room for improvement, but the error handling isn't trivial. I'd be happy to merge any PRs with improvements. |
while i implemented a reconnect callback for my app, i found a few glitches.
maybe some of them just mean my usage was wrong.
maybe there are a room for improvements in MQTT-C as well.
I don't want to make it reconnect on MQTT_ERROR_SEND_BUFFER_IS_FULL.
also, the underlying transport (in my case, mbedtls) can fail.
(examples/reconnect_subscriber.c just exit in that case. but
it isn't ideal for real applications.)
however, the callback needs to call mqtt_connect anyway because
of the locking protocol.
i workarounded it by having my reconnect callback
call MQTT_PAL_MUTEX_UNLOCK directly when it doesn't want to
or can't reconnect. but I feel it isn't ideal to have
PAL stuff in the user callback.
maybe mqtt_sync should not call the reconnect callback on MQTT_ERROR_SEND_BUFFER_IS_FULL in the first place. i can't imagine the case when it's useful.
maybe we can introduce some api (say, mqtt_reconnect_callback_failed)
to report the failure. (and unlock the mutex)
so that the reconnect callback can do something like the following:
mqtt_sync -> __mqtt_recv -> mqtt_pal_recvall
it means we need to keep client->socketfd valid even on an error state.
(or make mqtt_pal_recvall smart enough to deal with invalid socketfd.
it might not be simple depending on PAL implementations.)
it also means the reconnect callback need to provide valid socketfd
even on failure.
maybe we can skip __mqtt_recv unless MQTT_OK or MQTT_ERROR_SEND_BUFFER_IS_FULL
as __mqtt_send does.
The text was updated successfully, but these errors were encountered: