Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR Summary by QodoDisconnect stalled RTSP/TCP clients without interrupting other viewers
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1.
|
A send error other than a full buffer marked the client but left its socket open; without a read event the RTSP thread would keep its slot. The socket is now shut down as in the stall case, so the RTSP thread frees the connection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated after the automatic review (second commit). Hard send error without a read event: correct. The socket is now shut down on that path as well, as in the one-second stall case, so the RTSP thread sees the end of input and frees the connection. Tested on a Ruision F8 board (FH8856V200) with the second commit:
In the reset test the RTSP thread also saw the reset on its read side, so that test cannot show the case the review describes (an error with no read event); the change makes the cleanup independent of it. 🤖 Generated with Claude Code |
What was wrong
One RTSP/TCP client that stops reading freezes the stream for every other client, for as long as it stays stuck. Reproduced on a Ruision F8 board (FH8856V200): a test client that plays over TCP and then reads nothing for 10 s gave a second, normal client an 8.4 s gap in the video and an 8.7 s gap in the audio. A viewer on a wireless link that stalls for a few seconds does the same in real use; we saw three such 7 s gaps in an hour.
Why
One thread sends each frame to all clients in turn (
__rtp_send()walks the transfer list). For TCP clients the data is written to a non-blocking socket, and when the socket buffer is full the loops in__tcp_flush(),__rtp_send_eachconnection()and__rtcp_send_sr()wait (poll()for 100 ms, orusleep(1000)) and try again, with no limit. While they wait for one client, no other client gets anything, and the encoder's frames pile up or are lost.A client that fails is also returned as
FAILURE, which makeslist_map_inline()stop, so the clients after it in the list miss the rest of that frame.What this changes
__tcp_send_all()insrc/rtsp/rtsp.hsends a buffer completely. When the client takes no data forRTSP_TX_STALL_MS(1000 ms), it logs one line, marks the connection (tx_dead), and shuts the socket down. The RTSP thread then sees the end of input and frees the connection as it does for any client that leaves; the player can reconnect. A send error marks the connection the same way, without the log line.__tcp_flush(), the unstaged path of__rtp_send_eachconnection()and the interleaved branch of__rtcp_send_sr()use the helper.SUCCESSis returned, so the other clients still get the frame. UDP clients are unchanged.tx_deadis cleared when a connection slot is reused.How it was checked
./build.sh fhan-v2, no new warnings;./test.sh -apasses.Effect on other platforms
Shared RTSP code, every target. Only TCP clients that stop taking data are affected: they are now disconnected after about one second without progress (with the socket buffer the server sets, a client that falls behind has some seconds of slack before the buffer is full).
clock_gettime(CLOCK_MONOTONIC),poll()andshutdown()are POSIX;tools.calready uses the clock. The one-second limit matches the read side (#85, open), which closes a client that stalls in the middle of an interleaved packet after one second.Update after the automatic review
A second commit also shuts the socket down after a hard send error, so the RTSP thread frees such a client even without a read event. Tested on the board with viewers that reset their connection while being sent to: no connection left behind, the other viewer unaffected.
🤖 Generated with Claude Code