fix(ws_bridge): avoid WDT panics, RX poison, and incomplete HA sync - #309
Merged
Conversation
esp_websocket_client_stop() waits with portMAX_DELAY and can block for tens of seconds during DNS/TLS. Delegate it to a short-lived task so the 5s task WDT cannot panic-reboot the device. Co-authored-by: Cursor <cursoragent@cursor.com>
Leaving a completed payload in rx_accum_ when allocate() fails concatenates the next frame onto it and poisons every subsequent HA command. Also ignore remaining chunks of oversized messages (WS CONT and buffer_size TEXT splits) and skip empty payloads. Co-authored-by: Cursor <cursoragent@cursor.com>
…sync esp_websocket_client_send_text() returns -1 on client->lock timeout without aborting the socket. Dropping the backlog there discarded live declares. If any declare is lost, skip ws_bridge/sync so Home Assistant does not delete the missing entities. Co-authored-by: Cursor <cursoragent@cursor.com>
Multiple send_text waits of 1000ms in one loop() can approach the 5s task WDT, especially when command-event drains also send. Cap cumulative send time at 1200ms without shortening the per-send timeout that #305 needs to avoid connection abort. Co-authored-by: Cursor <cursoragent@cursor.com>
auth_ok is processed on the main loop while CONNECTED/DISCONNECTED is stored by the WS task. An unconditional store could set CONNECTED after the socket had already dropped, leaving is_connected() true until ping timeout. Co-authored-by: Cursor <cursoragent@cursor.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
force_reconnect_()cannot block the ESPHome loop long enough to trip the 5s task WDT (panic reboot).rx_accum_when the event pool is exhausted and cap/drop oversized frames so a single dropped DATA event cannot poison every later HA command.send_text()lock-timeout (-1is not always a socket abort), skipws_bridge/syncif any declare was dropped, share one 1200ms send budget perloop(), and CAS auth state so a disconnect cannot be revived.Test plan
python -m esphome compile tests/components/ws_bridge/test.esp32-idf.yaml(already passed locally)sync_entities: truewith a congested link: HA must not delete entities after a dropped declareMade with Cursor