You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks, this looks like the right direction. Copying the fd list before broadcasting fixes the mutex/reentrancy problem, and removing the client on httpd_ws_send_frame_async() failure should prevent stale entries from exhausting MAX_WEBSOCKET_CLIENTS.
One small issue before moving on: the new log lines index type_counts[type] even though the increment/decrement is guarded by type >= 0 && type < WS_TYPE_MAX. Could you guard the log value too, or validate type before adding the client?
Optional but useful: please log the return value from httpd_sess_trigger_close() if it fails, since that would help diagnose cases where the websocket registry was cleaned but the HTTP session was already gone.
Also, minor wording nit: httpd_ws_send_frame_async() is the ESP-IDF “send outside the request handler” API, not the callback-based async completion API. This PR handles immediate send failures, not later queued-send completion failures.
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
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
This change improves WebSocket connection handling by removing stale clients
when
httpd_ws_send_frame_async()fails.Additionally,
websocket_broadcast()now copies the client list while holdingthe mutex and performs the actual sends after releasing the mutex.
Problem
Under repeated WebSocket reconnects (built-in UI and external monitoring
clients), stale client entries could accumulate after failed async sends.
Over time this could exhaust
MAX_WEBSOCKET_CLIENTS, resulting in:429 Too Many Requestshttpd_accept_conn: error in accept (113)Solution
Broadcasting is performed after releasing the client mutex to avoid modifying
the client list while iterating over it during send failures.
Testing
Tested on a Bitaxe Gamma (Board 601, BM1370).
The miner was operated for several hours with both the built-in web UI and
additional external WebSocket monitoring clients.
After the change:
MAX_WEBSOCKET_CLIENTSwas observed