[Bug Report] SendEventAsync() never returns when DeviceClient gets disposed
Werner-Prbk opened this issue · 3 comments
Werner-Prbk commented
Context
- OS, version, SKU and CPU architecture used: Windows 10 Desktop x64 (also on linux arm32)
- Application's .NET Target Framework : .netcoreapp 3.1
- Device: Laptop (also on arm32 device with custom linux)
- SDK version used: 1.38.0
Issue description
SendEventAsync() never returns when DeviceClient gets disposed in ConnectionStatusChangesHandler.
Following the reconnection sample the DeviceClient is disposed and newly created when ConnectionStatusChangesHandler is called with (Disconnected, Retry_Expired). If another task is still busy with SendEventAsync() on the old (already disposed) DeviceClient, the method never returns.
Internet connection was cut off at 15:38:20. SendEventAsync() hangs forever:
Code sample exhibiting the issue
static async Task Main()
{
deviceClient = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Mqtt);
// IoT-Hub connection retry policy before exception is thrown.
// This should result in disconnected/retry_expired after a few seconds.
deviceClient.SetRetryPolicy(
new ExponentialBackoff(
6, // retry counter
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(10),
TimeSpan.FromSeconds(1)));
deviceClient.SetConnectionStatusChangesHandler((status, reason) =>
{
Print($"Connection status changed: {status}, {reason}");
if (reason == ConnectionStatusChangeReason.Retry_Expired)
{
Print("Dispose Device Client");
deviceClient.Dispose();
}
});
await deviceClient.OpenAsync();
Print("Connected");
try
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(5));
Print("Send message ... start");
await deviceClient.SendEventAsync(new Message());
Print("Send message ... OK");
}
}
catch (Exception e)
{
Print($"Periodic sender exception: {e.Message}. Exit.");
}
}
Logs
azabbasi commented
Thank you for reporting this issue, We are working on the fix and will publish it on the next nuget release.
azabbasi commented
azabbasi commented
We have checked-in the fix and will publish it on the next release.
Thank you for being a valuable contributor to the quality of the SDK.