Azure / azure-iot-sdk-csharp

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

[Bug Report] #3449

Open sebastian-bylinski opened 3 months ago

sebastian-bylinski commented 3 months ago

Context

Description of the issue

Using 2.0.0-preview004 in GWv2 gateway, call to OpenAsync to IotHub wipes message from IoTHub for the first time when connecting when device is offline before message has been send to IoTHub. It happens at random. Sometimes getting the message in the code, sometimes not. Out of 10 tries 3, worked 7 did not. Apparently this issue supposed to be corrected in GWV2, but it is not. The issue remains. It works fine when device is already connected to IoTHub when message has been sent.

Code sample exhibiting the issue

private static IotHubDeviceClient _iotHubClient;

try { var _connectionString = "HostName=;SharedAccessKeyName=device;SharedAccessKey=;Deviceid=";

IotHubClientAmqpSettings transport = new IotHubClientAmqpSettings();
    var options = new IotHubClientOptions
    {
        RetryPolicy = new IotHubClientFixedDelayRetryPolicy(0, TimeSpan.FromSeconds(3), true)
    };

    _iotHubClient = new IotHubDeviceClient(_connectionString, options);

    Task.Run
        (async () =>
        {
            try
            {
                await _iotHubClient.OpenAsync();
                await _iotHubClient.SetIncomingMessageCallbackAsync(MessageCallback);
            }
            catch (Exception e)
            {
                throw;
            }
        });
}
catch (Exception e)
{
    throw new Exception(e.ToString());
}

}

protected async Task MessageCallback(IncomingMessage message) { return MessageAcknowledgement.Abandon; }

Console log of the issue

andyk-ms commented 3 months ago

Thanks for the info.

For preview release, please update to the last good version: https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/preview_2023-08-14

For production stable setup, please use the latest version of the official SDK release here: https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2024-03-28

sebastian-bylinski commented 3 months ago

Andy,

I tried 2.0.0-preview007 with the same exact results. It seems that the success of getting messages from the IoT hub increased, however messages are still lost when connecting to the hub for the very first time.

Sebastian Bylinski

On Tue, Apr 16, 2024 at 12:52 PM Andy @.***> wrote:

Thanks for the info.

For preview release, please update to the last good version:

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

For production stable setup, please use the latest version of the official SDK release here: https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2024-03-28

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-iot-sdk-csharp/issues/3449#issuecomment-2059530394, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFAG3USCNGMGRTQH3EJFNTY5VJM3AVCNFSM6AAAAABFZTS5MCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJZGUZTAMZZGQ . You are receiving this because you authored the thread.Message ID: @.***>