MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

ManagedMqttClient.SubscribeAsync does not handle or inform about subscription errors

Open xnoreq opened this issue 1 year ago • 1 comments

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:

  1. MQTTnet version 4.3.3.952
  2. Optional: set up a MqttNetEventLogger to log verbose messages (to print the SubAck packet with subscription result code)
  3. 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.

xnoreq avatar Mar 20 '24 12:03 xnoreq

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?

xnoreq avatar Mar 20 '24 13:03 xnoreq

The latest version available at nuget should contain the change. It was released recently.

chkr1011 avatar Jun 08 '24 14:06 chkr1011