diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec
index e2bfb867..afcf1e8d 100644
--- a/Build/MQTTnet.nuspec
+++ b/Build/MQTTnet.nuspec
@@ -22,6 +22,7 @@
* [Server] Session takeover and keep alive timeout are now properly set in DISCONNECT packet.
* [Server] Fixed bug in PubRel packet generation (MQTTv5 only).
* [Server] Improved message processing performance (+ ~5%).
+* [Server] Fix wrong usage of client session items for undelivered messages.
Copyright Christian Kratky 2016-2020
MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin Blazor
diff --git a/Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs b/Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs
index 6fbaa933..ed46305c 100644
--- a/Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs
+++ b/Source/MQTTnet/MqttApplicationMessageReceivedEventArgs.cs
@@ -2,7 +2,7 @@
namespace MQTTnet
{
- public class MqttApplicationMessageReceivedEventArgs : EventArgs
+ public sealed class MqttApplicationMessageReceivedEventArgs : EventArgs
{
public MqttApplicationMessageReceivedEventArgs(string clientId, MqttApplicationMessage applicationMessage)
{
diff --git a/Source/MQTTnet/Server/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/MqttClientSessionsManager.cs
index 0dc95190..18b529e4 100644
--- a/Source/MQTTnet/Server/MqttClientSessionsManager.cs
+++ b/Source/MQTTnet/Server/MqttClientSessionsManager.cs
@@ -287,21 +287,21 @@ namespace MQTTnet.Server
return;
}
- var sender = queuedApplicationMessage.Sender;
- var senderClientId = sender?.ClientId ?? _options.ClientId;
+ var clientConnection = queuedApplicationMessage.Sender;
+ var senderClientId = clientConnection?.ClientId ?? _options.ClientId;
var applicationMessage = queuedApplicationMessage.ApplicationMessage;
var interceptor = _options.ApplicationMessageInterceptor;
if (interceptor != null)
{
- var interceptorContext = await InterceptApplicationMessageAsync(interceptor, sender, applicationMessage).ConfigureAwait(false);
+ var interceptorContext = await InterceptApplicationMessageAsync(interceptor, clientConnection, applicationMessage).ConfigureAwait(false);
if (interceptorContext != null)
{
if (interceptorContext.CloseConnection)
{
- if (sender != null)
+ if (clientConnection != null)
{
- await sender.StopAsync(MqttDisconnectReasonCode.NormalDisconnection).ConfigureAwait(false);
+ await clientConnection.StopAsync(MqttDisconnectReasonCode.NormalDisconnection).ConfigureAwait(false);
}
}
@@ -343,7 +343,8 @@ namespace MQTTnet.Server
return;
}
- await undeliveredMessageInterceptor.InterceptApplicationMessagePublishAsync(new MqttApplicationMessageInterceptorContext(senderClientId, sender?.Session?.Items, applicationMessage));
+ // The delegate signature is the same as for regular message interceptor. So the call is fine and just uses a different interceptor.
+ await InterceptApplicationMessageAsync(undeliveredMessageInterceptor, clientConnection, applicationMessage).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
@@ -427,12 +428,12 @@ namespace MQTTnet.Server
}
}
- async Task InterceptApplicationMessageAsync(IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection senderConnection, MqttApplicationMessage applicationMessage)
+ async Task InterceptApplicationMessageAsync(IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection clientConnection, MqttApplicationMessage applicationMessage)
{
string senderClientId;
IDictionary