mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

Clean start on first connection only

Open ralight opened this issue 6 years ago • 2 comments

How about if you could configure the clean start behaviour something like this:

mosquitto_int_option(mosq, MOSQ_OPT_CLEAN_START, ALWAYS);
mosquitto_int_option(mosq, MOSQ_OPT_CLEAN_START, FIRST_TIME_ONLY);

ralight avatar Oct 29 '19 11:10 ralight

Hi, @ralight , long time no see.

What's meaning of MOSQ_OPT_CLEAN_START? Clean session?

ethsonliu avatar Oct 30 '19 07:10 ethsonliu

MQTT v3 called the connect flag "clean start". This was changed to "clean session" in v3.1 and kept the same in v3.1.1. Now v5.0 has changed the name back to "clean start".

So yes, for MQTT v3.1.1 clients this would affect the "clean session" flag behaviour, but calling it "clean start" seems like the best choice for the future. This is especially true because it only really makes sense for a v5.0 client, where clean start only affects the session when you connect, not when you disconnect.

The rationale (which came up on an email that I've my answer pasted from), is to allow changing the behaviour from what happens currently (clean start is always set), to having it set on the first connection only. This allows the following:

  • Client connects with clean start set, to ensure old session state is removed
  • The client must be durable, so subscriptions and messages with QoS>1 are persisted
  • In the event that there is a disconnection cause by anything other than the user telling the client to disconnect, i.e. a temporary network failure, then libmosquitto will attempt to reconnect.
  • If ALWAYS is set, then the automatic reconnection would cause the session to be deleted on the broker.
  • If FIRST_TIME_ONLY is set, then the automatic reconnection would not set clean start, so that the client state remains persisted on the broker, and once reconnected the client can continue as normal.

Without this option, v5 clients can't make full use of the clean start feature.

ralight avatar Nov 05 '19 10:11 ralight