Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean start on first connection only #1479

Open
ralight opened this issue Oct 29, 2019 · 2 comments
Open

Clean start on first connection only #1479

ralight opened this issue Oct 29, 2019 · 2 comments
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.
Milestone

Comments

@ralight
Copy link
Contributor

ralight commented Oct 29, 2019

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 ralight added this to the 1.7 milestone Oct 29, 2019
@ralight ralight added Type: Enhancement A new feature for a minor or major release. Component: libmosquitto labels Oct 29, 2019
@ethsonliu
Copy link

Hi, @ralight , long time no see.

What's meaning of MOSQ_OPT_CLEAN_START? Clean session?

@ralight
Copy link
Contributor Author

ralight commented Nov 5, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.
Projects
None yet
Development

No branches or pull requests

2 participants