-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add MOSQ_OPT_DELAYED_ACK option #1932
base: develop
Are you sure you want to change the base?
Conversation
Signed-off-by: Linus Basig <[email protected]> Co-authored-by: Fabrizio Lazzaretti <[email protected]> Signed-off-by: Fabrizio Lazzaretti <[email protected]>
When did this change? I thought the library had always been pubacking after teh callback? |
@karlp I've checked, and it's been like this forever. I'm mostly inclined to say that we should just change the behaviour (and for QoS 2) without an option. For people who have quick callbacks it will make no difference, and those with long callbacks there If would only potentially be a problem with non-compliant brokers. If I did add it as an option, it would be with |
It did not surprise me that the library acknowledges before the message is handed over to the application; most libraries do that. I think the reason for that is that the specification is not very explicit about this situation. The MQTT specifications says:
Personally, I'm also in favor of changing the default behavior. As @karlp's reaction shows the "acknowledging before processing" behavior is very counter-intuitive and the specification does not provide any good reason to use it. Should I change the PR to send PUBACK and PUBCOMP after on_message was called? |
Hrm, I thought the paho python libs didn't ack until the callback returned, or something I was working with at least, I was explicitly demoing delays in the handlers. I'd be perfectly fine with switching the default, but this will likely lead to beahviour changes as broken clients will now cause unacked packets to build up in varous places, whereas right now, a client that crashes doesn't matter. |
We were using the paho.mqtt.c library before and it has the same "issue": https://github.com/eclipse/paho.mqtt.c/blob/master/src/MQTTProtocolClient.c#L326-L332 The same for the patho.mqtt.python: eclipse-paho/paho.mqtt.python#348 There are libraries that implement a delayable acknowledgment option like paho.mqtt.java (https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/IMqttAsyncClient.java#L822-L833) and some that delay it per default like mqtt.js (mqttjs/MQTT.js#697). I think pending acknowledgments shouldn't be a big problem. They can already occur if there is an issue with the network layer or the client crashes before he reads the PUBLISH message from the network buffer. In any way, as soon as the connection's Keep Alive period runs out, these pending acknowledgments should be cleaned up. |
I think on balance the best thing to do is add it as an option otherwise if it does cause problems there is nothing users can do other than downgrade, if it does cause a problem. So please update this to use Then we go: 2.1: Option available, but off by default |
I implemented the Regarding QoS 2: (for the following thoughts I assumed With the current implementation of QoS 2, delaying the sending of the As far as I see we have two options:
I personally am in favor of option 1 because QoS 2 sucks. the MQTT specification assumes that the sender and the receiver never crash or lose their state. Even if we go with option 2 we can't fulfill the promise of an "Exactly Once" processing guarantee in real-world conditions and option 1 is already as good as it gets if we ignore the possibility of a process crashing at the wrong moment. |
9f834df
to
feeca2b
Compare
Signed-off-by: Linus Basig <[email protected]> Co-authored-by: Fabrizio Lazzaretti <[email protected]> Signed-off-by: Fabrizio Lazzaretti <[email protected]>
feeca2b
to
7934634
Compare
d265cb9
to
192a092
Compare
Any news on when this might get reviewed/merged? |
@ralight any estimations? |
028adb2
to
604b69a
Compare
b7e2d3d
to
e715b04
Compare
Signed-off-by: Linus Basig [email protected]
Signed-off-by: Fabrizio Lazzaretti [email protected]
Thank you for contributing your time to the Mosquitto project!
Before you go any further, please note that we cannot accept contributions if
you haven't signed the Eclipse Contributor Agreement.
If you aren't able to do that, or just don't want to, please describe your bug
fix/feature change in an issue. For simple bug fixes it is can be just as easy
for us to be told about the problem and then go fix it directly.
Then please check the following list of things we ask for in your pull request:
If you are contributing a bugfix, is your work based off the fixes branch?make test
with your changes locally?01-keepalive-pingreq.py
fails, but it also fails on masterThis PR adds a method
mosquitto_delay_puback
. After callingmosquitto_delay_puback
the library will delay the PUBACK message required for QoS 1 message transfers until after theon_message
callback returns.This change ensures the message does not get lost if the client crashes during the processing of the message.
If the
mosquitto_delay_puback
is not called, the previous behavior (PUBACK before callingon_message
) applies.related issues:
Our use-case is a messaging middleware that forwards the messages to other systems and we need to maintain the "At Least Once" delivery guarantee of QoS 1.