Closed law-ko closed 8 months ago
Thank you for reporting this problem. We will look into this problem and discuss with you here.
@law-ko Can you help to provide the following information?
prvPublishToTopic
@chinglee-iot
Your esp-idf version: v5.0.1
Your iot-reference-esp32c3 tag or commit: latest
The application code which calls prvPublishToTopic:
char *jsonString = cJSON_PrintUnformatted(rootJSON);
prvPublishToTopic( xQoS, pcPubTopicBuffer, (char *) jsonString );
We have adjusted the code into our app that work with AWS IoT with desired
and reported
style. This is uncommon error to see and looking deeper into the code we don't know what was causing this.
The exception you shared indicates a LoadProhibited exception in the tasks.c. From the tasks.c in v5.0.1, the xTaskToNotify
is passed by parameters in prvPublishCommandCallback
. It looks like xTaskToNotify
points to an invalid address.
BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify,
uint32_t ulValue,
eNotifyAction eAction,
uint32_t * pulPreviousNotificationValue )
{
...
ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ]; /* This line has LoadProhibited exception. */
xTaskNotify(xTaskGenericNotify)
is called in the prvPublishCommandCallback
and is a member variable of input parameter pxCommandContext
.
pxCommandContext
points to a local variable xCommandContext
in prvPublishToTopic
. Therefore, it is on the stack of the task which calls prvPublishToTopic
.
static void prvPublishToTopic( MQTTQoS_t xQoS,
char * pcTopicName,
char * pcPayload )
{
...
MQTTAgentCommandInfo_t xCommandParams = { 0 };
...
xCommandContext.ulNotificationValue = ulPublishMessageId;
xCommandContext.xTaskToNotify = xTaskGetCurrentTaskHandle();
xCommandParams.blockTimeMs = subpubunsubconfigMAX_COMMAND_SEND_BLOCK_TIME_MS;
xCommandParams.cmdCompleteCallback = prvPublishCommandCallback;
xCommandParams.pCmdCompleteCallbackContext = &xCommandContext;
Base on these information, we can troubleshoot the following possible causes:
Stack overflow
Local variable xCommandContext
in prvPublishToTopic
may be corrupted if there is stack overflow. FreeRTOS supports stack overflow detection mechanism. You can reference this page to enable stack overflow checking.
Use after free
The prvPublishCommandCallback
is called from another task. If the task calls prvPublishToTopic
exited, the stack memory will be used by other task. The pxCommandContext
may point to memory modified by other task. We would like to suggest to check the status of the task which calls prvPublishToTopic
.
We also suggest you to run the sub_pub_unsub_demo only on your platform to see if this problem can be reproduced and feedback the result. This can help us to narrow down the problem.
@chinglee-iot Would it be possible that this crash is related to the MQTT_ProcessLoop
being blocked like xEventGroupWaitBit
?
@law-ko
MQTT_ProcessLoop
is blocked by transport interface receive function in receiveSingleIteration
and is only called in the prvMQTTAgentTask
.
static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
bool manageKeepAlive )
{
....
recvBytes = pContext->transportInterface.recv( pContext->transportInterface.pNetworkContext,
&( pContext->networkBuffer.pBuffer[ pContext->index ] ),
pContext->networkBuffer.size - pContext->index );
Could you help to provide the xEventGroupWaitBits
call in question so we can discuss it with you here?
Closing this issue due to inactivity. Feel free to re-open the issue if it persists.
The crash will occur after around 20000000 ticks, and happens when trying to send a new publish to AWS IoT. The program is set to publish to AWS IoT every 30 seconds.
The error occurs when performing
xTaskNotify
, which is coming from the example function provided in this repo.System information
Expected behavior A clear description of the expected behavior.
Screenshots or console output
Thank you.