mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-29 18:28:24 +02:00
MQTT: Fix esp_mqtt_client_stop deadlock
esp_mqtt_client_stop would lead to a deadlock (with itself) when called from the event handler. Updated comments to reflect that some functions should not be called from the event handler. Closes https://github.com/espressif/esp-mqtt/issues/163
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user