Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -1468,6 +1468,11 @@ static esp_err_t esp_websocket_client_close_with_optional_body(esp_websocket_cli
// Set closing bit to prevent from sending PING frames while connected
xEventGroupSetBits(client->status_bits, CLOSE_FRAME_SENT_BIT);

if (client->config->auto_reconnect && client->config->close_reconnect) {
// Client does not stop(STOPPED_BIT) with auto-reconnect-on-close
return ESP_OK;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLOSE_FRAME_SENT_BIT persists after failed send and reconnection

Medium Severity

When esp_websocket_client_send_close fails (e.g., transport error), esp_websocket_client_abort_connection is called which sets state to WEBSOCKET_STATE_WAIT_TIMEOUT for reconnection. However, CLOSE_FRAME_SENT_BIT is set unconditionally after send_close returns, regardless of success or failure. With the new early return, the client then reconnects with this bit still set, causing PINGs to be permanently suppressed on the new connection. Previously, a failed close would eventually trigger a force-stop, making this a non-issue. The bit should only be set if the close frame was actually sent successfully.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intentional - CLOSE_FRAME_SENT_BIT is cleared by the client-thread when it processes the disconnect.

}

if (STOPPED_BIT & xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, timeout)) {
return ESP_OK;
}
Expand Down
Loading