android icon indicating copy to clipboard operation
android copied to clipboard

Duplicate MQTT SUBSCRIBE for persistent sessions

Open JuliusFruitfly opened this issue 1 year ago • 3 comments

Owntracks seems to re-issue subscriptions for a persistent mqtt session even when the protocol version is set to 4 (3.1.1) and the 'session present' flag is set in the CONNACK

This is a shame as it generates a lot of traffic on an unreliable connection

Thanks.

  • App build number: 2.5.3 (420503003)
  • Android version: 14
  • Device: Xiaomi/Redmi Note 12
  • Installation source: Google Play

JuliusFruitfly avatar Nov 13 '24 16:11 JuliusFruitfly

It's a good shout - we always re-subscribe on reconnect.

The problem with only doing that when cleanSession=true is that if the broker is not persisting state, if the broker restarts, then it'll lose the session and no messages will be received by OT until it explicitly resubscribes. OT has no way of knowing when it reconnects whether or not a broker is holding an existing session, hence we always subscribe.

Could have it as a config setting for people who explicitly want to turn this behaviour off?

growse avatar Nov 23 '24 19:11 growse

Andrew,

I think this problem is fixed in MQTT 3.1.1. The CONNACK has a 'session present' flag which is only set if you have connected to a valid, pre-existing session - so no subscribes necessary .

No extra configuration is required because the flag will only ever be set if 'mqttProtocolLevel' is set to 4.

This will only ever be a issue if you decide to change the default for mqttProtocolLevel in the future

Thanks

On Sat, 23 Nov 2024 at 19:20, Andrew Rowson @.***> wrote:

It's a good shout - we always re-subscribe on reconnect.

The problem with only doing that when cleanSession=true is that if the broker is not persisting state, if the broker restarts, then it'll lose the session and no messages will be received by OT until it explicitly resubscribes. OT has no way of knowing when it reconnects whether or not a broker is holding an existing session, hence we always subscribe.

Could have it as a config setting for people who explicitly want to turn this behaviour off?

— Reply to this email directly, view it on GitHub https://github.com/owntracks/android/issues/1912#issuecomment-2495627299, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARWEFQEAWCCIE5EIKNIPOYD2CDIPVAVCNFSM6AAAAABRW4WWMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJVGYZDOMRZHE . You are receiving this because you authored the thread.Message ID: @.***>

--

  • Neil

JuliusFruitfly avatar Nov 24 '24 20:11 JuliusFruitfly

Aha, excellent. Let me tinker.

growse avatar Nov 25 '24 08:11 growse