Skip to content

Fix one stalled client blocking WebSocket writes to all windows - #725

Merged
AlbertShown merged 1 commit into
webui-dev:mainfrom
ViktorJannicke:fix/send-mutex
Oct 22, 2026
Merged

AlbertShown merged 1 commit into
webui-dev:mainfrom
ViktorJannicke:fix/send-mutex

Conversation

@ViktorJannicke

Copy link
Copy Markdown
Contributor

Fixes #723

_webui_send_client_ws() no longer holds the process-wide _webui.mutex_send around mg_websocket_write(). CivetWeb's mg_websocket_write_exec() already locks the connection for the whole frame, and close_connection() takes the same lock. Frames to one connection therefore stay whole and ordered, and a client that stops reading blocks only its own writes. The unused mutex_send field, init and destroy are removed. Nothing changes in src/civetweb/ or include/webui.h.

Verified on Linux x64 with the reproducer from the issue: a stalled client on window A, and webui_script() round trips to window B in headless Chromium for 65 s.

  • Before: 3 calls, p50 30045 ms.
  • After: 1552 calls, p50 42 ms, max 46 ms.
  • 3 runs each.

Stress test: one multi-client window, 8 threads calling webui_run() with frames of 0 to 128 KiB, back-to-back webui.call()s from the page, and about 330 extra clients connecting and dropping (some with RST).

  • All 1600 frames arrived intact and in order. All call replies were correct.
  • 3 plain runs and 3 ASan/UBSan runs: no findings.
  • 1 TSan run: no race that is not also present at efac0e2.

🤖 Generated with Claude Code

`_webui_send_client_ws()` held the process-wide `mutex_send` around
`mg_websocket_write()`. CivetWeb already locks the connection for the whole
frame, so the global lock only made a client that stops reading block every
other window and client for up to `request_timeout_ms` (30 s) per frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlbertShown

Copy link
Copy Markdown
Member

Thank you for the PR, I think we still need to add "tcp_nodelay", "1" to HTTP options. I will do it after merging.

@AlbertShown
AlbertShown merged commit 6bf50aa into webui-dev:main Oct 22, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One client that stops reading blocks WebSocket writes to every window (global mutex_send)

2 participants