Skip to content

Conversation

PaoloPasinetti
Copy link

@PaoloPasinetti PaoloPasinetti commented Jan 9, 2025

Description

This fixes an issue that occurred when auto-reconnection is enabled, and the client is disconnected from the server. In this situation, if the esp_websocket_client_stop() method is called, the caller could remain stuck waiting for a maximum time equal to half of reconnect_timeout_ms.

This fix allows the esp_websocket_client_task to be woken up when it is waiting to reconnect, so it can be closed promptly when requested by esp_websocket_client_stop().

Testing

Procedure:

  1. Start the client using a bad server url/IP, configuring disable_auto_reconnect = false and reconnect_timeout_ms = 180000
  2. When the client is in WEBSOCKET_STATE_WAIT_TIMEOUT, call esp_websocket_client_stop()

Before these changes, the esp_websocket_client_stop() method could remain stuck for up to 90000 ms, half of reconnect_timeout_ms. With the implementation of this fix, the internal client task is woken up and stopped


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant
Copy link

CLAassistant commented Jan 9, 2025

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 9, 2025
@github-actions github-actions bot changed the title fix(websocket): avoid long waiting time when waiting to auto-reconnect fix(websocket): avoid long waiting time when waiting to auto-reconnect (IDFGH-14393) Jan 9, 2025
@PaoloPasinetti PaoloPasinetti changed the title fix(websocket): avoid long waiting time when waiting to auto-reconnect (IDFGH-14393) fix(websocket): avoid long stop time when waiting to auto-reconnect (IDFGH-14393) Jan 9, 2025
@glmfe glmfe self-requested a review September 12, 2025 12:21
Copy link
Collaborator

@glmfe glmfe left a comment

Choose a reason for hiding this comment

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

LGTM

@glmfe
Copy link
Collaborator

glmfe commented Sep 12, 2025

@PaoloPasinetti , please, resolve the merge conflicts so that we can submit this

@glmfe
Copy link
Collaborator

glmfe commented Sep 18, 2025

@PaoloPasinetti , thanks for the updates. The target pipelines are failing but it seems that the server we use for tests is down (wss://echo.websocket.events). lets wait a while to be sure that the pipelines are passing and then I'll merge this.

@glmfe glmfe self-assigned this Sep 18, 2025
@espressif-bot espressif-bot assigned glmfe and unassigned glmfe Sep 19, 2025
@glmfe
Copy link
Collaborator

glmfe commented Sep 19, 2025

@PaoloPasinetti,

I just merged a fix to the pipeline issue, please, rebase your branch. thanks!

This commit fixes an issue that occurred when auto-reconnection is enabled,
and the client is disconnected from the server. In this situation, if the
esp_websocket_client_stop() method is called, the caller could remain stuck
waiting for a maximum time equal to half of wait_timeout_ms.

This fix allows the esp_websocket_client_task to be woken up when it is
waiting to reconnect, so it can be closed promptly when requested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants