esp-protocols icon indicating copy to clipboard operation
esp-protocols copied to clipboard

fix(websocket): avoid long stop time when waiting to auto-reconnect (IDFGH-14393)

Open PaoloPasinetti opened this issue 10 months ago • 1 comments

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:

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

PaoloPasinetti avatar Jan 09 '25 13:01 PaoloPasinetti

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 09 '25 13:01 CLAassistant

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

glmfe avatar Sep 12 '25 12:09 glmfe

@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 avatar Sep 18 '25 12:09 glmfe

@PaoloPasinetti,

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

glmfe avatar Sep 19 '25 12:09 glmfe