diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec
index d3fdeb50..2c200893 100644
--- a/Build/MQTTnet.nuspec
+++ b/Build/MQTTnet.nuspec
@@ -12,34 +12,14 @@
trueMQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol.
-* [Core] Added all builders to the MQTT factory.
-* [Core] Removed global logger and refactored logging (BREAKING CHANGE!).
* [Core] Improved memory management when working with large payloads.
-* [Client] Renamed _MqttClientConnectResult_ to _MqttClientConnectResult_ (BREAKING CHANGE!).
* [Client] The OS will now choose the best TLS version to use. It is no longer fixed to 1.3 etc. (thanks to @patagonaa, #1271).
* [Client] Exposed user properties and reason string in subscribe result.
* [Client] Exposed user properties and reason string in unsubscribe result.
-* [ManagedClient] Extended ReconnectAsync (thanks to @nvsnkv, #1202).
-* [ManagedClient] Improved Amazon AWS support (thanks to @scottbrogden-iheartmedia, #1209).
-* [ManagedClient] Fixed bug that allowed invalid subscriptions (Thanks to @marcelwinh).
-* [Server] Added support for _RetainHandling_ (MQTTv5, BREAKING CHANGE!).
-* [Server] Added support for _NoLocal_ (MQTTv5, BREAKING CHANGE!).
-* [Server] Added support for _SubscriptionIdentifier_ (MQTTv5, BREAKING CHANGE!).
-* [Server] Server now reports supported features properly after successful connection (MQTTv5, BREAKING CHANGE!).
-* [Server] Fixed a memory/performance leak when using QoS Level 1.
-* [Server] Exposed connection timestamp in client status.
-* [Server] Refactored connection management code.
-* [Server] Exposed more details in _MqttServerClientConnectedEventArgs_.
-* [Server] Processing all pending messages before stopping (thanks to @AblEdge, #1234).
-* [Server] Added support for a custom exception handler in _MqttServerMultiThreadedApplicationMessageInterceptorDelegate_.
-* [Server] Removed logger from _MqttServerMultiThreadedApplicationMessageInterceptorDelegate_ (BREAKING CHANGE!).
-* [Server] Fixed a memory leak when deleting sessions.
-* [Server] Fixed timestamp check in server keep-alive monitor (thanks to @logicaloud, #1277).
* [Server] Added support for returning individual subscription errors (#80 thanks to @jimch)
* [Server] Improved topic filter comparisons (support for $).
-* [Server] Fixed wrong "IsSessionPresent" result (thanks to @logicaloud, #1268).
* [Server] Added more MQTTv5 response information to all interceptors (BREAKING CHANGE!).
-* [MQTTnet.Server] Moved server project to a dedicated GitHub repository.
+* [Server] Improved session management for MQTT v5 (#1294, thanks to @logicaloud).
Git commit: $gitCommit
Copyright Christian Kratky 2016-2021
diff --git a/MQTTnet.noUWP.sln b/MQTTnet.noUWP.sln
index 3d842a5e..5fcfbb87 100644
--- a/MQTTnet.noUWP.sln
+++ b/MQTTnet.noUWP.sln
@@ -45,8 +45,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.AspNetCore.Tests",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Tests.csproj", "{9C7106CA-96B8-4ABE-B3B4-9357AB8ACB41}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Server", "Source\MQTTnet.Server\MQTTnet.Server.csproj", "{DADEA836-5CC3-474C-A2D8-4D0F31118CD7}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Extensions.WebSocket4Net", "Source\MQTTnet.Extensions.WebSocket4Net\MQTTnet.Extensions.WebSocket4Net.csproj", "{9AE2F8DA-4178-470B-B8C4-88BE1DAE7D5F}"
EndProject
Global
diff --git a/Source/MQTTnet/Server/Internal/MqttClient.cs b/Source/MQTTnet/Server/Internal/MqttClient.cs
index 6f5d5f90..00b92d1b 100644
--- a/Source/MQTTnet/Server/Internal/MqttClient.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClient.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -96,11 +96,6 @@ namespace MQTTnet.Server
ChannelAdapter.ResetStatistics();
}
- public void Dispose()
- {
- _cancellationToken.Dispose();
- }
-
public async Task RunAsync()
{
_logger.Info("Client '{0}': Session started.", Id);
diff --git a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
index c722a45f..c4fe2c57 100644
--- a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
+++ b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
@@ -103,7 +103,7 @@ namespace MQTTnet.Server
connAckPacket = _connAckPacketFactory.Create(connectionValidatorContext);
// Pass connAckPacket so that IsSessionPresent flag can be set if the client session already exists
- client = await CreateClientConnection(connectPacket, connAckPacket, channelAdapter, connectionValidatorContext.SessionItems).ConfigureAwait(false);
+ client = await CreateClientConnection(connectPacket, connAckPacket, channelAdapter, connectionValidatorContext).ConfigureAwait(false);
await client.SendPacketAsync(connAckPacket, cancellationToken).ConfigureAwait(false);
@@ -138,7 +138,7 @@ namespace MQTTnet.Server
_clients.Remove(client.Id);
}
- if (!_options.EnablePersistentSessions)
+ if ((!_options.EnablePersistentSessions) || (!clientConnection.Session.IsPersistent))
{
await DeleteSessionAsync(client.Id).ConfigureAwait(false);
}
@@ -422,11 +422,36 @@ namespace MQTTnet.Server
async Task CreateClientConnection(
MqttConnectPacket connectPacket,
MqttConnAckPacket connAckPacket,
- IMqttChannelAdapter channelAdapter,
- IDictionary