Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
468 stars 492 forks source link

[Bug Report] [v2] Multiple calls to direct methond after reconnect #3354

Closed jenscski closed 1 year ago

jenscski commented 1 year ago

Context

Description of the issue

When a connection is automatically reconnected (e.g. network drop or similiar), direct method calls is called twice (possibly one more for each reconnect)

I have tested with both disabling my network, and turning "Enable connection to IoT Hub" on and off.

The reason for the error is that MqttTransportHandler.OpenAsync is called upon reconnect, but MqttTransportHandler.CloseAsync is not, so the HandleReceivedMessageAsync method is added again to the MqttClient.ApplicationMessageReceivedAsync event.

Code sample exhibiting the issue

Console log of the issue

tmahmood-microsoft commented 1 year ago

Hi @jenscski, thank you so much for evaluating previews/v2 and reporting this issue. I was able to reproduce and fix the issue, you can find the latest code changes here: https://github.com/Azure/azure-iot-sdk-csharp/pull/3359

Please let me know if it still does not work for you or if you face any more issues.

helynranta commented 1 year ago

Hi @tmahmood-microsoft, we had similar issue and I was able to verify that your fix solves it. Can you publish new preview package which includes this?

tmahmood-microsoft commented 1 year ago

@helynranta thank you for confirming the fix. Yes I am currently in process of publishing a new preview package. Should have it for you in a day or two.

tmahmood-microsoft commented 1 year ago

Hi @helynranta, @jenscski I am attaching link to the latest release package for v2 preview containing this fix, please let me know if you face any more issues and thank you for evaluating the preview release.

https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/preview_2023-08-14