stevenlovegrove / MqttDotNet

.net Implementation of the client half of the MQTT messaging protocol. MQTT is a lightweight, open specification publish and subscribe protocol cheifly developed by IBM. Details of MQTT can be found at http://mqtt.org.
MIT License
153 stars 91 forks source link

Incorrect incoming QoS 2 behaviour #3

Closed ralight closed 9 years ago

ralight commented 11 years ago

When a message is received from the broker with QoS=2, it is released to the client with OnMessageReceived() as soon as the PUBLISH is received. What should happen is the client stores the message information, responds with a PUBREC and then when a PUBREL is received it should release the stored message information to the client using OnMessageReceived(). The current behaviour means that "exactly once" delivery may be violated.

stevenlovegrove commented 11 years ago

Thanks for this report. It does sound like we're misshandling QoS 2 messages. I no longer actively develop (or use) this library but accept patches from the community. Perhaps one of the active users would like to submit a patch?

ericvoid commented 9 years ago

I'm quite late, but this actually doesn't sound like a problem. The specs (both 3.1 and 3.1.1) says that the Application Message can be processed when the PUBLISH is received OR when the PUBREL is received. Refer to the Flows chapter.

Now, what truly makes QoS 2 guarantee the "exactly once delivery" is the storage of the packet id (or message id) in an incoming messages set. When the sender sends the PUBREL packet, it means "release this packet id from the incoming messages set, the next message with that packet id will be a different one".

stevenlovegrove commented 9 years ago

Thanks @ericvoid. We did pay close attention to the flows at the time of implementation, so I'm relieved to here that it sounds like we didn't mess things up after all! I'm going to close this issue now. If someone strongly disagrees, please open it again.