Hello dear Azure IoT Edge team,
for a customer of ours we are currently trying to utilize the reported/desired property functionality of module and device twins. The customer decided to manage all configuration parameters that are important to multiple modules within the device properties, in order to prevent "multiple sources of truth".
The problem we face is that the devices are required to be resilient to network outages. While we encounter our desired behavior of the module client, being able to retrieve the module twin even when there is no internet connection available, we sadly see a different behavior of the device client when trying to retrieve the device twin. How can we accomplish retrieving the device twin from inside a module, when the device has no internet/hub connection?
Our demo code looks like this:
var deviceClient = DeviceClient.CreateFromConnectionString("REDACTED"));
var deviceTwin = await deviceClient.GetTwinAsync();
await deviceClient.SetDesiredPropertyUpdateCallbackAsync(DevicePropertiesUpdatedAsync, null);
The exception/stack strace we receive when calling deviceClient.GetTwinAsync():
Unhandled exception. Microsoft.Azure.Devices.Client.Exceptions.IotHubCommunicationException: Transient network error occurred, please retry.
---> System.Net.Sockets.SocketException (11): Resource temporarily unavailable
at Microsoft.Azure.Devices.Client.Transport.AmqpIoT.AmqpIoTTransport.InitializeAsync(TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpIoTConnector.OpenConnectionAsync(TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpConnectionHolder.EnsureConnectionAsync(TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpConnectionHolder.OpenSessionAsync(DeviceIdentity deviceIdentity, TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.AmqpIoT.AmqpUnit.EnsureSessionIsOpenAsync(TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.AmqpIoT.AmqpUnit.OpenAsync(TimeSpan timeout)
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpTransportHandler.OpenAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler.OpenAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass27_0.<<ExecuteWithErrorHandlingAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
--- End of inner exception stack trace ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass38_0.<<OpenInternalAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.EnsureOpenedAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass29_0.<<SendTwinGetAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.SendTwinGetAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.InternalClient.GetTwinAsync()
at Camera.Services.Settings.SettingsService.InitializeAsync() in /app/Services/Settings/SettingsService.cs:line 35
at Camera.Services.Hosted.CameraService.StartAsync(CancellationToken cancellationToken) in /app/Services/Hosted/CameraService.cs:line 24
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Camera.Program.Main(String[] args) in /app/Program.cs:line 14
at Camera.Program.<Main>(String[] args)
Azure IoT Edge Runtime Version: iotedge 1.1.0
Operating System: Ubuntu 18.04 LTS
SDK: Microsoft.Azure.Devices.Client 1.35.0