Azure / azure-iot-arduino

Azure IoT library for the Arduino
Other
167 stars 96 forks source link

Refreshing SAS token results in "SSL closed the connection" error #83

Closed photomoose closed 4 years ago

photomoose commented 5 years ago

Description of the issue:

My device uses the LL APIs to continuously send device to cloud messages to the IOT Hub every 20 seconds.IoTHubClient_LL_DoWork() is executed every 100ms.

After about an hour, the connection status callback is invoked with the following values:

Connection Status: IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, Reason: IOTHUB_CLIENT_CONNECTION_NO_NETWORK

The trace log outputs the following error:

/Documents/Arduino/libraries/AzureIoTUtility/src/adapters/tlsio_arduino.c Func:tlsio_arduino_dowork Line:454 SSL closed the connection.

Digging around in the code, I believe this is a problem that occurs when refreshing the SAS token.

If I configure the SAS token lifetime to 5 mins (as shown in the code below), I notice the problem occurs just after 5 minutes.

int sasTokenLifetime = 300;
if (IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_SAS_TOKEN_LIFETIME, &sasTokenLifetime) != IOTHUB_CLIENT_OK)
{
    (void)printf("IOT: Failed to set SAS Token Lifetime.\r\n");
}
photomoose commented 4 years ago

Closing, haven't seen this occur in recent versions of the SDK.