Skip to content

Commit

Permalink
Merge pull request #626 from euripedesrocha/websocket/fix_race_aborti…
Browse files Browse the repository at this point in the history
…ng_connection

Fix race condition when client set to not reconnect
  • Loading branch information
david-cermak authored Oct 31, 2024
2 parents fbd296f + 0d8f2a6 commit a353702
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ static esp_err_t esp_websocket_client_abort_connection(esp_websocket_client_hand
ESP_WS_CLIENT_STATE_CHECK(TAG, client, return ESP_FAIL);
esp_transport_close(client->transport);

if (client->config->auto_reconnect) {
if (!client->config->auto_reconnect) {
client->run = false;
client->state = WEBSOCKET_STATE_UNKNOW;
} else {
client->reconnect_tick_ms = _tick_get_ms();
ESP_LOGI(TAG, "Reconnect after %d ms", client->wait_timeout_ms);
client->error_handle.error_type = error_type;
client->state = WEBSOCKET_STATE_WAIT_TIMEOUT;
}

client->error_handle.error_type = error_type;
client->state = WEBSOCKET_STATE_WAIT_TIMEOUT;
esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_DISCONNECTED, NULL, 0);
return ESP_OK;
}
Expand Down Expand Up @@ -1051,10 +1053,6 @@ static void esp_websocket_client_task(void *pv)
break;
case WEBSOCKET_STATE_WAIT_TIMEOUT:

if (!client->config->auto_reconnect) {
client->run = false;
break;
}
if (_tick_get_ms() - client->reconnect_tick_ms > client->wait_timeout_ms) {
client->state = WEBSOCKET_STATE_INIT;
client->reconnect_tick_ms = _tick_get_ms();
Expand Down

0 comments on commit a353702

Please sign in to comment.