fix: Allow mqtt client to gracefully disconnect when stop

Previously the failure to create a disconnect message would lead the
client to an incorrect state if called in the process of destroy.
This commit is contained in:
Euripedes Rocha Filho
2025-09-09 16:19:41 +02:00
committed by Rocha Euripedes
parent 09fb84db9d
commit 6bc96ca0b3

View File

@@ -1942,10 +1942,7 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
// Only send the disconnect message if the client is connected // Only send the disconnect message if the client is connected
if (client->state == MQTT_STATE_CONNECTED) { if (client->state == MQTT_STATE_CONNECTED) {
if (send_disconnect_msg(client) != ESP_OK) { send_disconnect_msg(client);
MQTT_API_UNLOCK(client);
return ESP_FAIL;
}
} }
client->run = false; client->run = false;