From 4ab956abd1d375376a7406259d35765d12df4bcd Mon Sep 17 00:00:00 2001 From: Christian <6939810+chkr1011@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:35:39 +0200 Subject: [PATCH] Change behavior of NoMatchingSubscribers (#1975) Change behavior of NoMatchingSubscribers. --- .github/workflows/ReleaseNotes.md | 1 + .../MQTTnet/Server/Internal/MqttClientSessionsManager.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index ca1d1be3..b1e9464a 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -1,5 +1,6 @@ * [Core] Optimized packet serialization of PUBACK and PUBREC packets for protocol version 5.0.0 (#1939, thanks to @Y-Sindo). * [Core] The package inspector is now fully async (#1941). * [Client] Added a dedicated exception when the client is not connected (#1954, thanks to @marcpiulachs). +* [Server] The server will no longer send _NoMatchingSubscribers_ when the actual subscription was non success (#1965, BREAKING CHANGE!). * [ManagedClient] Added a new event (SubscriptionsChangedAsync) which is fired when a subscription or unsubscription was made (#1894, thanks to @pdufrene). * [TopicTemplate] Added new extension which provides a template engine for topics (#1932, thanks to @simonthum). diff --git a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs index 4f6864b8..8a949c9d 100644 --- a/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs +++ b/Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs @@ -257,7 +257,12 @@ namespace MQTTnet.Server if (matchingSubscribersCount == 0) { - reasonCode = (int)MqttPubAckReasonCode.NoMatchingSubscribers; + if (reasonCode == (int)MqttPubAckReasonCode.Success) + { + // Only change the value if it was success. Otherwise, we would hide an error or not authorized status. + reasonCode = (int)MqttPubAckReasonCode.NoMatchingSubscribers; + } + await FireApplicationMessageNotConsumedEvent(applicationMessage, senderId).ConfigureAwait(false); } }