From 257211fc7a98d62895a6f16f673de7d9a17c5f4a Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Thu, 11 Jun 2020 12:41:48 +0200 Subject: [PATCH] Moved undeliveredMessageInterceptor to local variable to avoid threading issues. --- Source/MQTTnet/Server/MqttClientSessionsManager.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet/Server/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/MqttClientSessionsManager.cs index a0f0bf2e..d27a366f 100644 --- a/Source/MQTTnet/Server/MqttClientSessionsManager.cs +++ b/Source/MQTTnet/Server/MqttClientSessionsManager.cs @@ -238,12 +238,14 @@ namespace MQTTnet.Server if (deliveryCount == 0) { - if (_options.UndeliveredMessageInterceptor == null) + var undeliveredMessageInterceptor = _options.UndeliveredMessageInterceptor; + + if (undeliveredMessageInterceptor == null) { return; } - await _options.UndeliveredMessageInterceptor.InterceptApplicationMessagePublishAsync(new MqttApplicationMessageInterceptorContext(sender?.ClientId, sender?.Session?.Items, applicationMessage)); + await undeliveredMessageInterceptor.InterceptApplicationMessagePublishAsync(new MqttApplicationMessageInterceptorContext(sender?.ClientId, sender?.Session?.Items, applicationMessage)); } } catch (OperationCanceledException)