Skip to content

Commit

Permalink
fix(websocket): wait for task on destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Jan 28, 2025
1 parent e069ae7 commit d252280
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,18 @@ esp_err_t esp_websocket_client_destroy(esp_websocket_client_handle_t client)
if (client == NULL) {
return ESP_ERR_INVALID_ARG;
}

/* A running client cannot be destroyed from the websocket task/event handler */
TaskHandle_t running_task = xTaskGetCurrentTaskHandle();
if (running_task == client->task_handle) {
ESP_LOGE(TAG, "Client cannot be destroyed from websocket task");
return ESP_FAIL;
}

if (client->run) {
esp_websocket_client_stop(client);
}
xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
destroy_and_free_resources(client);
return ESP_OK;
}
Expand Down

0 comments on commit d252280

Please sign in to comment.