0

I've recently started working with the Azure-Iot-SDK and wonder how to investigate this behaviour. My application is ok with sending messages to the IoT hub for some time, but suddenly just stops sending. Without an error or anything else that helps me find the rootcause for this. Just restarting the application (a service to be precise) is enough to get it working again.

Code is like this (on DataChangedEvent) :

try {    
    deviceClient = DeviceClient.Create(connectionString, x509Certificate, tType);
    Log("Start sending message")
    await deviceClient.SendEventAsync(message);
    DoLogging("Done sending!");
}
catch (Exception e)
{
    moreLogging("Error occurred");
}

Somehow the "Done sending!" message stops appearing in the logs, but the "Start sending message" keeps coming. Does anyone have any suggestions how to proceed?

gidJac
  • 3
  • 2

2 Answers2

0

From SendEventAsync method implementation,

The async operation shall retry until time specified in OperationTimeoutInMilliseconds property expire or unrecoverable error(authentication or quota exceed) occurs.

So check the OperationTimeoutInMilliseconds value to see if there is an error occurs after reach the timeout.

Meanwhile, you can monitor the connection status by registering such handler:

deviceClient.SetConnectionStatusChangesHandler(ConnectionStatusChangeHandler);

The handler may look like this:

                static void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
                {
                    Console.WriteLine();
                    Console.WriteLine("Connection Status Changed to {0}", status);
                    Console.WriteLine("Connection Status Changed Reason is {0}", reason);
                    Console.WriteLine();
                }

And you can try this way to see if it helps:

   await deviceClient.SendEventAsync(eventMessage).ConfigureAwait(false);
Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Hi Rita, the ''OperationTimeOut was the default 240s, but no errors appear. The connection status does not change and adding the ConfigureAwait does not make a difference. I'm starting to suspect network stability as Resource monitor shows very limited traffic once the Done sending messages stop appearing. I'll investigate further. – gidJac Apr 06 '18 at 13:45
  • Thanks for sharing. You can try [other languages SDK](https://github.com/Azure/azure-iot-sdks#microsoft-azure-iot-sdks-1) to see if it reproduce your issue. – Rita Han Apr 09 '18 at 06:38
0

If you haven't fixed the timeouts, here's a tip for you: try re-creating your IoT Hub in another region ("West US" works stably for me).

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Dmytro Gokun
  • 405
  • 3
  • 24