Repository navigation
fix(gateway): wake WebChat writes on the lws service thread - #127
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
lws_callback_on_writable updates the poll set without the per-thread lock. Replies and provider-status broadcasts called it from the agent thread while lws_service ran on the gateway thread, racing pollfd updates and a closing wsi. Queue the frame, cancel the service wait, and mark writable only from EVENT_WAIT_CANCELLED. Co-authored-by: esadrianno <esadrianno@gmail.com>
Collaborator
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.
WebChat replies and provider-status broadcasts called
lws_callback_on_writable()from the agent thread whilelws_service()ran on the gateway thread. In libwebsockets 4.3 that call updates the poll set without the per-thread lock, so a live reply can race the service thread and touch awsithatLWS_CALLBACK_CLOSEDis already tearing down. The process can crash, or the queued frame is never flushed and the browser never sees the reply.ws_send_toandws_broadcast_textnow only queue the text and calllws_cancel_service(), which is safe from another thread.LWS_CALLBACK_EVENT_WAIT_CANCELLED(delivered on the service thread to every protocol, with a fakewsi) callsws_on_service_cancel()to mark real connections that still have queued text.http_stopclears the stored context beforelws_context_destroy.Validation:
make test_ws(including the new wake tests) passed.src/gateway/ws.c,http_lws.c, andhttp.ccompiled with-Wall -Wextraagainst libwebsockets 4.3.3.GATEWAY=0 make testbuilt and ran the unit suite;test_routes_hardwarestill tries to link after its GATEWAY=0 skip line, which is existing makefile behavior and unrelated to this change.