Merge branch 'bugfix/stop_from_event' into 'master'

MQTT: Fix esp_mqtt_client_stop deadlock

See merge request espressif/esp-mqtt!74
This commit is contained in:
David Čermák
2020-08-17 22:01:08 +08:00
2 changed files with 13 additions and 0 deletions

View File

@ -239,6 +239,9 @@ esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client);
/**
* @brief Stops mqtt client tasks
*
* * Notes:
* - Cannot be called from the mqtt event handler
*
* @param client mqtt client handle
*
* @return ESP_OK on success
@ -306,6 +309,9 @@ int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic,
/**
* @brief Destroys the client handle
*
* Notes:
* - Cannot be called from the mqtt event handler
*
* @param client mqtt client handle
*
* @return ESP_OK

View File

@ -1481,6 +1481,13 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
{
MQTT_API_LOCK(client);
if (client->run) {
/* A running client cannot be stopped from the MQTT task/event handler */
TaskHandle_t running_task = xTaskGetCurrentTaskHandle();
if (running_task == client->task_handle) {
ESP_LOGE(TAG, "Client cannot be stopped from MQTT task");
return ESP_FAIL;
}
// Only send the disconnect message if the client is connected
if(client->state == MQTT_STATE_CONNECTED) {
// Notify the broker we are disconnecting