moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.27k stars 814 forks source link

Avoid to pub retries on timeout #697

Closed andsel closed 1 year ago

andsel commented 1 year ago

Originally Moquette sent retries of PUB and PUBREL packets basing on a ACK timeout. This made to re-send PUB also on open TCP connections. With MQTT5 - 4.4.0-1 it's specified that retries must happen only on reconnected not clean start sessions.

What it does

This PR stores the MQTT version into the Session instance and use that to keep the existing behavior for inflight resends (happening on a timeout basis on ACK received) in case the version is MQTT 3.1 or MQTT 3.1.1. When the version of the Session is MQTT 5 it removes the resend on PUB ACK timeouts and switch to send only in case the same client reconnects with cleanStart = 0 and there is any peding publishes in the flight zone to get acknowledged.

To test this use the raw Client has been extended, so now can also subscribe and collect publish messages.

andsel commented 1 year ago

Hi @hylkevds, this is one of the MQTT5 PRs to solve the items in meta #695. It mainly changes the MQTTConnection and Session to send the retries of inflight PUB and PUBREL only when a client with same clientd and not cleanStart connects, and not on timeout basis like implemented for MQTT3. I ask if you would like be the reviewer of this changes :-)

hylkevds commented 1 year ago

Of course I'll be happy to review :) May take a bit though...

andsel commented 1 year ago

Thank you a lot, no hurry :-)