MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

CleanSession==false not working

Open ManniAT opened this issue 4 years ago • 5 comments

I use ManagedClient (Windows .net core) with Mosquitto as server. When I first connect I set CleanSession to false. After this I subscribe to several topics and receive Messages. After a call to StopAsync the message flow stops (intended). When I call StartAsync again (passing the same parameters including CleanSession==false) I am connected and can send messages. But I don't receive any in ApplicationMessageReceived handler.

I thought CleanSession==false kepps subscriptions alive (restortes them). Am I doing something wrong or is this an intended behaviour?

ManniAT avatar May 06 '20 11:05 ManniAT

From https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages/:

When the clean session flag is set to false, the broker creates a persistent session for the client. All information and messages are preserved until the next time that the client requests a clean session. If the clean session flag is set to false and the broker already has a session available for the client, it uses the existing session and delivers previously queued messages to the client.

As far as I understand it, this is a bug. @chkr1011 Any ideas here?

SeppPenner avatar Jun 09 '20 19:06 SeppPenner

@chkr1011 any news on this? Or exist there any extension points to hook in to make this scenario reliable?

gfoidl avatar Dec 03 '21 21:12 gfoidl

The managed client currently does not support existing sessions. The reason is that this would also require a handling for exisitng subscriptions. This includes separating them into different lists in order to determine whether a subscription is "new" (added while being disconnected) or already present at the server.

I you need this feature I recommend to use the regular client from the core library. There you need to implement retries, reconnects on your own but you can also decide how to deal with such situations as a described above.

chkr1011 avatar Dec 05 '21 11:12 chkr1011

Since https://github.com/dotnet/MQTTnet/issues/492 and https://github.com/dotnet/MQTTnet/pull/836 seem to be done, this should be possible now, I guess?

SeppPenner avatar Jun 14 '22 06:06 SeppPenner

is there any estimate on when is this going to be fixed?

angelonardone avatar Aug 23 '23 16:08 angelonardone