astrorafael / twisted-mqtt

MQTT Client protocol for Twisted.
MIT License
30 stars 11 forks source link

DuplIcates in QoS2 #1

Closed astrorafael closed 8 years ago

astrorafael commented 8 years ago

In the current, when a given packet is not acknowledged, this packet and all the following are retransmitted. This is ok in QoS 1 but is a bug in QoS 2, since you will receive duplicates, violating the QoS2 guarantee.

RATIONALE

When designing the MAX InFlight Message window I realized that selective retransmission would yield messages out of order at the receiving side. I took for granted that message ordering was implied in the standard. Thus, I chose to retransmit all messages from a given one (the one with missing ACK). This would be fine for QoS1 but I overlooked QoS 2 guarantees.

However, when installing the mosquitto broker, I came acros a not saying that if message ordering was impornat you should set the MAX_INFLIGHT_MEAGE parameter to 1. Then I realized my mistake interpreting the standard.

astrorafael commented 8 years ago

After reviwing the code, it turns out that the retransmission mechanism is selective, based on reactor's callLater() with arguments. Only a tiny probablility remains that pending ACK messages are all retransmitted when the connection has just been lost. This is not an issue for the time being.