mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 18:43:10 +08:00
Fix MQTT5 'IsPersisted' session flag handling (#1300)
This commit is contained in:
@@ -8,11 +8,6 @@ namespace MQTTnet.Server.Internal
|
||||
{
|
||||
readonly DateTime _createdTimestamp = DateTime.UtcNow;
|
||||
|
||||
/// <summary>
|
||||
/// Session should persist if CleanSession was set to false (Mqtt3) or if SessionExpiryInterval != 0 (Mqtt5)
|
||||
/// </summary>
|
||||
readonly bool _isPersistent;
|
||||
|
||||
public MqttClientSession(
|
||||
string clientId,
|
||||
IDictionary<object, object> items,
|
||||
@@ -24,17 +19,19 @@ namespace MQTTnet.Server.Internal
|
||||
{
|
||||
ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
|
||||
Items = items ?? throw new ArgumentNullException(nameof(items));
|
||||
|
||||
IsPersistent = isPersistent;
|
||||
SubscriptionsManager = new MqttClientSubscriptionsManager(this, serverOptions, eventDispatcher, retainedMessagesManager);
|
||||
ApplicationMessagesQueue = new MqttClientSessionApplicationMessagesQueue(serverOptions);
|
||||
_isPersistent = isPersistent;
|
||||
}
|
||||
|
||||
public string ClientId { get; }
|
||||
|
||||
public bool IsCleanSession { get; set; } = true;
|
||||
|
||||
public bool IsPersistent => _isPersistent;
|
||||
/// <summary>
|
||||
/// Session should persist if CleanSession was set to false (Mqtt3) or if SessionExpiryInterval != 0 (Mqtt5)
|
||||
/// </summary>
|
||||
public bool IsPersistent { get; set; }
|
||||
|
||||
public MqttApplicationMessage WillMessage { get; set; }
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ namespace MQTTnet.Server.Internal
|
||||
// in each time it connects.
|
||||
|
||||
// Persist if SessionExpiryInterval != 0, but may start with a clean session
|
||||
sessionShouldPersist = context.SessionExpiryInterval != 0;
|
||||
sessionShouldPersist = context.SessionExpiryInterval.GetValueOrDefault() != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -540,6 +540,8 @@ namespace MQTTnet.Server.Internal
|
||||
else
|
||||
{
|
||||
_logger.Verbose("Reusing existing session of client '{0}'.", connectPacket.ClientId);
|
||||
// Session persistence could change for MQTT 5 clients that reconnect with different SessionExpiryInterval
|
||||
session.IsPersistent = sessionShouldPersist;
|
||||
connAckPacket.IsSessionPresent = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user