Repository navigation
video: a WebSocket viewer's backlog waits in the ring, not the send queue - #53
Conversation
Previous review (2026-11-27)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head The fix holds up: a WebSocket viewer's backlog now stays in the ring instead of piling into the send queue, and the new slow-start test fails on the base and passes on this head. Only two small follow-ups remain, neither blocking. Minor (2)
|
Previous review (2026-11-27)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head The ring-not-queue fix still holds at ffd91ec, and this update adds no new problems. Since the last review at e4857ea, both earlier minors are fixed: a slowly draining WebSocket viewer now counts as making progress, and prefix-stage timeouts are logged as "stalled". Minor (1)
Withdrawn: the unlabelled hard-error drop at videoview.cpp:656 is unchanged from the base, so it is out of scope here. |
…ueue
WebSocket::send() queues what the socket will not take and reports the
whole frame as sent, so the viewer loop never saw a full socket and kept
queueing until the 1 MiB limit closed the connection ("output queue
full", logged as a write error). A viewer on a long path joining a
12 Mbit/s stream was dropped on every join, as the data from the last
keyframe is more than the queue holds while TCP is still in slow start.
The viewer now stops while the WebSocket has output queued, leaving the
backlog in the ring where the lapped and chronically-behind limits
apply. A viewer that used its write budget while still behind asks to be
called again rather than waiting for the next ingest.
… is logged as one Bytes leaving the WebSocket queue now count as progress, as bytes accepted by a raw viewer's socket do, so a viewer draining one frame slowly is not dropped while data is still moving. A viewer that stops taking the stream prefix is logged as stalled rather than closed.
…Socket viewers A viewer that takes one queued frame over several stall times is not dropped, and a viewer stalled before the stream prefix is logged as stalled. Both fail without the previous commit.
95ba01f to
04c201f
Compare
Previous review (2026-11-27)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head The ring-not-queue fix and the slow-drain and stall-label changes all hold at 04c201f, with one minor gap left. Since the last review at ffd91ec, the missing test coverage is fixed: both new tests fail without af760c5 and pass on this head. Minor (1)
The earlier review's "no new problems" and "a slowly draining viewer is not stalled" are superseded by the item above; the withdrawn hard-error drop stays out of scope. |
A WebSocket viewer's queued video also drains when a pong is flushed on the read path. Only the flush on the write path refreshed the stall timer, so a slow viewer that sends pings could be dropped as stalled while its video was still going out. The WebSocket now counts the bytes it has handed to the socket and the viewer compares that count.
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head The new commit e836205 fixes the one open item, and no new problems turned up at this head. Since the last review at 04c201f, the ping-path progress gap is fixed. WebSocket::flush() now counts every byte it sends (websocket.cpp:550), and on_writable() refreshes the stall timer whenever that count moves (videoview.cpp:598). So output flushed while answering a ping counts as progress. The new test (test_video_view.py:803) fails on 04c201f and passes on this head. Not fully reviewed: the WSS/TLS version of a slow, pinging viewer and the full test suite were not run; only the video and WebSocket tests were. |
A WebSocket video viewer on a long path was disconnected every time it joined a high-bitrate stream, and reconnected into the same thing.
Cause
WebSocket::send()queues what the socket will not take and reports the whole frame as sent. The viewer loop invideoview.cpptherefore never saw a full socket, and kept queueing until the 1 MiBWS_MAX_TX_QUEUElimit closed the connection:A new viewer is sent everything from the last keyframe. On a 12.5 Mbit/s stream that is about 1.5 MB, more than the queue holds while TCP is still in slow start on a long path. Viewers close to the proxy drain it in time; viewers in Japan and the US were dropped on every join (264 times in one log).
Fix
Testing
test_ws_viewer_slow_to_start_is_not_dropped: a WebSocket viewer with a small receive buffer does not read while 3 MB is published, then must receive more than 2 MB as a verbatim span of the stream with no disconnect. It fails before the fix with "output queue full" and passes after.pytest tests --ignore=tests/webadmin: 419 passed, 1 skipped.