mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-27 09:17:29 +02:00
fix(websocket): release client-lock during WEBSOCKET_EVENT_DATA
This resolves: 1) Deadlock when trying to reserve a lock in WEBSOCKET_EVENT_DATA, but lock is held by a thread trying to send a websocket message. 2) High latency caused by writers serialized with WEBSOCKET_EVENT_DATA while calling esp_websocket_client_send(), even when TCP window has enough space for the entire message being queued to send. Multiple writers are still serialized at fragment boundaries, but only with other writers and websocket error updates. Fixes #625
This commit is contained in:
@ -1071,12 +1071,6 @@ static void esp_websocket_client_task(void *pv)
|
||||
break;
|
||||
}
|
||||
client->ping_tick_ms = _tick_get_ms();
|
||||
|
||||
if (esp_websocket_client_recv(client) == ESP_FAIL) {
|
||||
ESP_LOGE(TAG, "Error receive data");
|
||||
esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WEBSOCKET_STATE_WAIT_TIMEOUT:
|
||||
|
||||
@ -1113,6 +1107,13 @@ static void esp_websocket_client_task(void *pv)
|
||||
xSemaphoreTakeRecursive(client->lock, lock_timeout);
|
||||
esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
|
||||
xSemaphoreGiveRecursive(client->lock);
|
||||
} else if (read_select > 0) {
|
||||
if (esp_websocket_client_recv(client) == ESP_FAIL) {
|
||||
ESP_LOGE(TAG, "Error receive data");
|
||||
xSemaphoreTakeRecursive(client->lock, lock_timeout);
|
||||
esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
|
||||
xSemaphoreGiveRecursive(client->lock);
|
||||
}
|
||||
}
|
||||
} else if (WEBSOCKET_STATE_WAIT_TIMEOUT == client->state) {
|
||||
// waiting for reconnecting...
|
||||
|
Reference in New Issue
Block a user