Skip to content

Commit ca2956e

Browse files
committed
fix(websocket): Fix race conditions and memory leak
- Add state check in abort_connection to prevent double-close - Fix memory leak: free errormsg_buffer on disconnect - Reset connection state on reconnect to prevent stale data - Implement lock ordering for separate TX lock mode - Added sdkconfig.ci.tx_lock config
1 parent 69bd459 commit ca2956e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,9 @@ static esp_err_t esp_websocket_client_recv(esp_websocket_client_handle_t client)
10761076

10771077
xSemaphoreGiveRecursive(client->lock); // Release client->lock
10781078

1079-
// Now acquire tx_lock (safe - no circular wait possible)
1080-
if (xSemaphoreTakeRecursive(client->tx_lock, portMAX_DELAY) != pdPASS) {
1081-
ESP_LOGE(TAG, "Failed to acquire tx_lock for PONG");
1079+
// Now acquire tx_lock with timeout (consistent with PING/CLOSE handling)
1080+
if (xSemaphoreTakeRecursive(client->tx_lock, WEBSOCKET_TX_LOCK_TIMEOUT_MS) != pdPASS) {
1081+
ESP_LOGE(TAG, "Could not lock ws-client within %d timeout for PONG", WEBSOCKET_TX_LOCK_TIMEOUT_MS);
10821082
xSemaphoreTakeRecursive(client->lock, portMAX_DELAY); // Re-acquire client->lock before returning
10831083
return ESP_OK; // Return gracefully, caller expects client->lock to be held
10841084
}

0 commit comments

Comments
 (0)