aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
984 stars 633 forks source link

OTA_Shutdown() not releasing resources #1910

Open coratron opened 6 months ago

coratron commented 6 months ago

I am using the following:

The problem:

The OTA task consumes about 10kB of RAM. Calling OTA_Shutdown() should release the resources but it is not.

Confirmed with logs by checking the RAM before and after, as well as verbose logging which ends in I (100117) AWS_OTA: OTA Agent stopped.

I am basing my code on the OTA example. In other words, the result should be reproducible by measuring the RAM watermark before aws_iot_ota() and at the end of it.

coratron commented 6 months ago

Leaving this here until someone has a look:

I have solved the issue and recommend modifying the otaThread function in the example to:

void* otaThread(void* pParam)
{
    /* Calling OTA agent task. */
    OTA_EventProcessingTask(pParam);
    LogInfo(("OTA Agent stopped."));

    pthread_detach(pthread_self());
    pthread_exit(NULL);

    return NULL;
}

Otherwise the resources allocated to the thread will not be released.

coratron commented 6 months ago

Restarting OTA is the next issue after releasing the resources : the system gets caught here on the second start up pass:

  else
        {
            /* Drop all events that created after OTA_Shutdown. */
            resetEventQueue();
        }

in OTA_Init

paulbartell commented 5 months ago

@coratron Thanks for the bug report. Would you mind opening a Pull Request with your suggested fix?

ActoryOu commented 2 weeks ago

Hi @coratron, Could you help take a look on #1923 to check if this is the patch you want?

Thank you.