ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.

Home Page:https://ossrs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue of abnormal disconnection of TCP connection in live streaming pull end unable to release

juntaoliu opened this issue · comments

When using the cluster mode of SRS, consider the following scenarios:

When using a player to play a live stream from the edge, the following scenario should be considered:

When establishing a playback connection (e.g., C1) from the edge, the edge will initiate an ingest connection (C2) with the origin server to pull the live stream. If the stream exists at that time, the live stream can be played normally. This is the normal usage mode of the cluster mode.

However, if the live stream has not started streaming yet or if there is no such stream at all, the connection C1 from the edge will be maintained until the live stream arrives.

If, at this time, a network anomaly causes the communication between the player and the edge to be disconnected (such as network interruption or sudden power failure), in this case, the playback connection C1 established by the player does not disconnect properly because the player side does not have the opportunity to send a TCP connection termination FIN.

In this situation, the connection C1 becomes a persistent TCP connection, but the client side of this TCP connection cannot be recovered.

If the live stream starts pushing, the edge will attempt to send data into the TCP connection and will find that the TCP connection is no longer active, so it will close the TCP connection.

But what if this stream doesn't exist at all?

Then this TCP connection C1 will continue to exist and will not be released until SRS is restarted.

TRANS_BY_GPT3

This should be similar to when one side of the network cable is unplugged, and the other side needs to detect the disconnection. Generally, in the TCP layer, KEEPALIVE is used to detect whether the connection is disconnected.

TRANS_BY_GPT3

I changed it to SRS_PERF_SO_KEEPALIVE, which is not enabled by default. That's how SRS2 is now.
In SRS3, if you think it should be enabled by the user, you can change it to read the configuration. If there are no issues with enabling it, then it should be enabled by default.

TRANS_BY_GPT3

Fixed.