esp-protocols
esp-protocols copied to clipboard
fix(websocket): avoid long stop time when waiting to auto-reconnect (IDFGH-14393)
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:
- Start the client using a bad server url/IP, configuring
disable_auto_reconnect = falseandreconnect_timeout_ms = 180000 - When the client is in
WEBSOCKET_STATE_WAIT_TIMEOUT, callesp_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 , please, resolve the merge conflicts so that we can submit this
@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.
@PaoloPasinetti,
I just merged a fix to the pipeline issue, please, rebase your branch. thanks!