MQTTnet
MQTTnet copied to clipboard
ManagedMqttClient.SubscribeAsync does not handle or inform about subscription errors
Describe the bug
ManagedMqttClient simply calls await InternalClient.SubscribeAsync(subscribeOptionsBuilder.Build()).ConfigureAwait(false); without handling the return value.
The return value of type MqttClientSubscribeResult contains a collection of MqttClientSubscribeResultItem which have a ResultCode.
This result code can indicate subscription errors, such as 0x8F (TopicFilterInvalid).
I'd rate this as a SEVERE bug, because the caller does not know whether subscriptions succeeded or failed.
Which component is your bug related to?
- ManagedClient
To Reproduce
Steps to reproduce the behavior:
- MQTTnet version 4.3.3.952
- Optional: set up a
MqttNetEventLoggerto log verbose messages (to print the SubAck packet with subscription result code) - Call
await client.SubscribeAsync(invalidTopic)
Expected behavior
Either await client.SubscribeAsync(invalidTopic) should fail with an exception, or due to the background processing and event-based architecture of ManagedMqttClient fire a new event such as "SubscriptionsFailedAsync" with args that contain the subscription result code.
It looks like this is already implemented on master with the event SubscriptionsChangedAsync (commit aabf180b23c20879175d4102062ce84eb0563d7a).
When is this going to be release as a nuget package?
The latest version available at nuget should contain the change. It was released recently.