Fix cleanup of client sessions

This commit is contained in:
Christian Kratky
2017-11-08 00:49:49 +01:00
parent f481c704c9
commit 7e48746944
4 changed files with 6 additions and 13 deletions
@@ -14,10 +14,10 @@ namespace MQTTnet.Core.Adapter
{
public class MqttChannelCommunicationAdapter : IMqttCommunicationAdapter
{
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private readonly ILogger<MqttChannelCommunicationAdapter> _logger;
private readonly IMqttCommunicationChannel _channel;
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
public MqttChannelCommunicationAdapter(IMqttCommunicationChannel channel, IMqttPacketSerializer serializer, ILogger<MqttChannelCommunicationAdapter> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -68,7 +68,6 @@ namespace MQTTnet.Core.Server
try
{
// ReSharper disable once UseNullPropagation
if (_options.Storage != null)
{
await _options.Storage.SaveRetainedMessagesAsync(allRetainedMessages);
+2 -8
View File
@@ -13,11 +13,11 @@ using Microsoft.Extensions.Options;
namespace MQTTnet.Core.Server
{
public sealed class MqttClientSession : IDisposable
public sealed class MqttClientSession
{
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager;
private readonly HashSet<ushort> _unacknowledgedPublishPackets = new HashSet<ushort>();
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager;
private readonly MqttClientSubscriptionsManager _subscriptionsManager;
private readonly MqttClientSessionsManager _sessionsManager;
private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue;
@@ -113,12 +113,6 @@ namespace MQTTnet.Core.Server
_pendingMessagesQueue.Enqueue(publishPacket);
}
public void Dispose()
{
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
}
private async Task ReceivePacketsAsync(IMqttCommunicationAdapter adapter, CancellationToken cancellationToken)
{
try
@@ -164,10 +164,10 @@ namespace MQTTnet.Core.Server
if (connectPacket.CleanSession)
{
_clientSessions.Remove(connectPacket.ClientId);
clientSession.Dispose();
clientSession.Stop();
clientSession = null;
_logger.LogTrace("Disposed existing session of client '{0}'.", connectPacket.ClientId);
_logger.LogTrace("Stopped existing session of client '{0}'.", connectPacket.ClientId);
}
else
{