Regarding clean sessions

Skip to first unread message

Chaitanya Munukutla

Dec 24, 2020, 12:54:40 PM12/24/20

I'm implementing an MQTT v5 compatible broker and I think I'm a bit stuck at the stateless / persistent sessions concept.

  1. When the CONNECT packet is sent to broker and cleanSession is set to true, should the broker clear sessions stored elsewhere for the same clientID? 
  2. There is a sessionExists flag on the CONNACK header. In case a client already has a persistent stored on the broker (which gets disconnected for whatever reasons) and later connects asking for a clean session, should the broker invalidate the earlier stored session, create a session without any state? If the broker has already invalidated the earlier sessions, should the sessionExists flag be set to true or false?

Dustin Sallings

Dec 24, 2020, 1:40:47 PM12/24/20
Yes, if the cleanSession flag is set, you should destroy any history of the given session.

Some clients/apps can't deal with earlier state.  cleanSession ensures the current client and its current connection has complete knowledge of what's been done.

To learn more about MQTT please visit
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages