Azure / azure-iot-sdk-csharp

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

Device Client Reconnects After Extended 'Disconnected_Retrying' State Without Entering 'Retry_Expired' as Documented #3468

Open Padmanaabhah opened 4 months ago

Padmanaabhah commented 4 months ago

Description:

Issue Summary: With the latest device client version, we have observed that the device enters the 'Disconnected_Retrying' status with the reason 'Communication_Error' and connects back even if the network is restored after 2 days. According to the documentation, it should enter 'retry_expired' after exhausting the retry attempts and timeout period.

Detailed Description:

Expected Behavior: The device should transition from 'Disconnected_Retrying' to 'retry_expired' after the retry period of 20 minutes is exhausted, as per the documentation.

Steps to Reproduce:

  1. Deploy the latest device client version in a lab environment.
  2. Induce a communication error to trigger the 'Disconnected_Retrying' state.
  3. Monitor the device status for state transitions.

Actual Behavior:

We need help understanding the following:

Any guidance or insights into this behavior would be greatly appreciated.

timtay-microsoft commented 3 months ago

It does appear the documentation around this behavior is incorrect/outdated.

The expectation here should be that, by default, the client will attempt to reconnect forever (with attempts slowing down over time). The operation timeout has no bearing on this and is only relevant to individual attempts to send a message, get the twin, etc.

If you want the client to eventually give up on reconnecting, then you will need to provide a custom retry policy that dictates at what point the SDK should stop retrying.

The only caveat here is that this SDK will implicitly try to open the connection for you when you try to send a message, get the twin, etc. so you may see the behavior you outlined above if you are sending that message when the device client is currently closed.