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.
https://ossrs.io
MIT License
25.87k stars 5.39k forks source link

Not being able to reconnect after network unavailability #4173

Closed RelioXx closed 2 months ago

RelioXx commented 2 months ago

Describe the bug I have a client who often disconnects from the SRS server because of connectivity issues in their area. When the server attempts to reconnect automatically, SRS shows the following error message:

[2024-09-07 13:49:49.478][ERROR][15][40y6mec3][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/livestream is busy thread [15][40y6mec3]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:263][errno=11] thread [15][40y6mec3]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:457][errno=11] thread [15][40y6mec3]: acquire_publish() [./src/app/srs_app_rtmp_conn.cpp:1078][errno=11](Resource temporarily unavailable)

Do you have any suggestions for avoiding this error? I'm considering whether SRS should disregard the current stream service and create a new one, but I'm not sure how to implement this.

Version SRS v5.0-r3 using default configuration

To Reproduce With any stream client stream in rtmp, force a disconnection due to network and then reconnect

suzp1984 commented 2 months ago

It will take a few seconds to let SRS remove the stream records. One solution is before you republish the stream, query the streams. curl http://localhost:1985/api/v1/streams/ get result:

{ "code": 0, "server": "vid-05t951p", "service": "0dpj008s", "pid": "17211", "streams": [ { "id": "vid-o3r5w78", "name": "test", "vhost": "vid-7f9n237", "app": "live", "tcUrl": "rtmp://localhost:1935/live", "url": "/live/test", "live_ms": 1725712716120, "clients": 1, "frames": 0, "send_bytes": 4384, "recv_bytes": 479328, "kbps": { "recv_30s": 0, "send_30s": 0 }, "publish": { "active": true, "cid": "1x881deq" }, "video": { "codec": "H264", "profile": "High", "level": "3.2", "width": 768, "height": 320 }, "audio": { "codec": "AAC", "sample_rate": 44100, "channel": 2, "profile": "LC" } } ] }

if you want to publish app/test, the stream {"name": "test", "app": "live",} match and conflict with your stream, then delete it by api: curl -X "DELETE" http://localhost:1985/api/v1/clients/1x881deq The 1x881deq come from there:

  "publish": {
    "active": true,
    "cid": "1x881deq"
  },

After this query and delete API, then I think you will never meet this error again.

RelioXx commented 2 months ago

Thanks will test it