IotNetworkMbedtls_Cleanup() from MQTT demo in AWS_IoT_Device don't returns

I’m using the AWS IoT Device packet included in Keil, with the MQTT library:

I’ve modified the iot_demo_mqtt.c and iot_demo.c examples to make it connect to a mosquitto broker, using TLS. It works fine and makes all the publications and subscriptions.
But when finishing there is some code that cleans the connection that doesn’t seems to work:

    /* Clean up the network stack if initialized. */
    if( networkInitialized == true )
    {
        IotDemoNetwork_Cleanup();
    }

    /* Clean up the SDK if initialized. */
    if( sdkInitialized == true )
    {
        IotSdk_Cleanup();
    }

IotDemoNetwork_Cleanup() don’t returns and if I comment it, IotSdk_Cleanup dont works also, jumps to prvTaskExitError().

IotDemoNetwork_Cleanup calls to IotNetworkMbedtls_Cleanup, seems that can’t close correctly the TLS connection.

I want to be able to recover from a disconnection, but if I try to reconnect again without disconnecting and cleaning everything there are some network and tasks related errors.

Hi @arodriguez

It seems you are using an old version of MQTT library and mqtt demo which is deprecated and no longer maintained. So could you move to the latest library and demo applications? The README has necessary documentation to get started. The libraries can also be obtained through CMSIS packs: MDK5 Software Packs