From f0ea13c07f783ed6de401b0c7ba3de411b505b9e Mon Sep 17 00:00:00 2001
From: logicaloud <47704763+logicaloud@users.noreply.github.com>
Date: Sat, 13 Nov 2021 22:05:54 +1300
Subject: [PATCH] Fix MQTT 3.1.1 session persistence when CleanSession=1
(#1294)
---
.../Server/Internal/MqttClientSession.cs | 14 ++++-
.../Internal/MqttClientSessionsManager.cs | 41 +++++++++++---
Tests/MQTTnet.Core.Tests/Server/General.cs | 4 +-
.../Server/MqttSubscriptionsManager_Tests.cs | 5 +-
.../Server/Session_Tests.cs | 54 ++++++++++++++++++-
.../MQTTnet.Core.Tests/Server/Status_Tests.cs | 6 +--
6 files changed, 107 insertions(+), 17 deletions(-)
diff --git a/Source/MQTTnet/Server/Internal/MqttClientSession.cs b/Source/MQTTnet/Server/Internal/MqttClientSession.cs
index 3f68fdfdf..291b3e5aa 100644
--- a/Source/MQTTnet/Server/Internal/MqttClientSession.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClientSession.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using MQTTnet.Server.Status;
@@ -8,24 +8,34 @@ public sealed class MqttClientSession : IDisposable
{
readonly DateTime _createdTimestamp = DateTime.UtcNow;
+ ///
+ /// Session should persist if CleanSession was set to false (Mqtt3) or if SessionExpiryInterval != 0 (Mqtt5)
+ ///
+ readonly bool _isPersistent;
+
public MqttClientSession(
string clientId,
IDictionary