srs icon indicating copy to clipboard operation
srs copied to clipboard

SrsLiveSource not release when forward hook failed

Open chukeer opened this issue 1 year ago • 2 comments

After the forward HTTP hook callback fails, the SrsLiveSource is not released, resulting in an error reporting "stream busy" upon the next stream push.

Version of the code.

1bd65f338 (2024-09-01 17:02:21 +0800) - (srs/6.0release) Refine release action. <winlin>

Example of a configuration file.

vhost __defaultVhost__ {
    forward {
        enabled on;
        backend http://127.0.0.1:22/forward;
    }

    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}

Stream method: ffmpeg -re -stream_loop -1 -i record-time.mp4 -c copy -f flv rtmp://10.8.69.50:1935/live/166zmh

The callback at http://127.0.0.1:22/forward will return a failure. The log from the first streaming attempt is as follows.

[2024-11-29 19:29:28.055][ERROR][897894][373ku012][11] serve error code=3009(HttpParseHeader)(HTTP parse header failed) : service cycle : rtmp: stream service : hub publish : create forwarders : create backend applied=1 : get forward ba
ckend failed, backend=http://127.0.0.1:22/forward : http: on_forward_backend failed, client_id=373ku012, url=http://127.0.0.1:22/forward, request={"action":"on_forward","server_id":"vid-oawkh82","service_id":"86a00o3t","client_id":"373k
u012","ip":"172.19.73.83","vhost":"__defaultVhost__","app":"live","tcUrl":"rtmp://10.8.69.50:1935/live","stream":"166zmh","param":"?dySecret=aafd3aaea75f9c632b05ae3c7e0e7675"}, response=, code=32708 : http: client post : http: parse res
ponse : parse message : parse 21B, nparsed=1, err=30/HPE_STRICT strict mode assertion failed
thread [897894][373ku012]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:265][errno=11]
thread [897894][373ku012]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:459][errno=11]
thread [897894][373ku012]: on_publish() [./src/app/srs_app_source.cpp:2594][errno=11]
thread [897894][373ku012]: on_publish() [./src/app/srs_app_source.cpp:1131][errno=11]
thread [897894][373ku012]: create_forwarders() [./src/app/srs_app_source.cpp:1474][errno=11]
thread [897894][373ku012]: create_backend_forwarders() [./src/app/srs_app_source.cpp:1528][errno=11]
thread [897894][373ku012]: on_forward_backend() [./src/app/srs_app_http_hooks.cpp:553][errno=11]
thread [897894][373ku012]: do_post() [./src/app/srs_app_http_hooks.cpp:614][errno=11]
thread [897894][373ku012]: post() [./src/protocol/srs_protocol_http_client.cpp:355][errno=11]
thread [897894][373ku012]: parse_message() [./src/protocol/srs_protocol_http_conn.cpp:103][errno=11]
thread [897894][373ku012]: parse_message_imp() [./src/protocol/srs_protocol_http_conn.cpp:136][errno=11](Resource temporarily unavailable)

Then, change the forward address to a normal address, attempt to re-stream, and an error occurs indicating "stream busy.

[2024-11-29 19:29:38.896][ERROR][897894][46r4840p][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/166zmh is busy
thread [897894][46r4840p]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:265][errno=11]
thread [897894][46r4840p]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:459][errno=11]
thread [897894][46r4840p]: acquire_publish() [./src/app/srs_app_rtmp_conn.cpp:1080][errno=11](Resource temporarily unavailable)
[2024-11-29 19:29:38.896][INFO][897894][kwi40486] TCP: clear zombies=1 resources, conns=1, removing=0, unsubs=0

In SrsRtmpConn::publishing, the call to acquire_publish fails. According to the comments, this error should be ignored, but there is no indication of a call to release_publish elsewhere.

    // TODO: FIXME: Should refine the state of publishing.
    srs_error_t acquire_err = acquire_publish(source);
    if ((err = acquire_err) == srs_success) {
        // use isolate thread to recv,
        // @see: https://github.com/ossrs/srs/issues/237
        SrsPublishRecvThread rtrd(rtmp, req, srs_netfd_fileno(stfd), 0, this, source, _srs_context->get_id());
        err = do_publishing(source, &rtrd);
        rtrd.stop();
    }
    
    // Release and callback when acquire publishing success, if not, we should ignore, because the source
    // is not published by this session.
    if (acquire_err == srs_success) {
        release_publish(source);
        http_hooks_on_unpublish();
    }

TRANS_BY_GPT4

chukeer avatar Nov 29 '24 11:11 chukeer

The issue is also present in version 6.0-a1. [2025-03-10 18:55:25.541][ERROR][15849][33p0q7f4][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/33920003917_1_0_1078_video is busy [2025-03-10 18:55:27.601][ERROR][15849][05bgl683][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/33920003917_1_0_1078_video is busy

It is uncertain whether subsequent versions have implemented improvements.

TRANS_BY_GPT4

terry8204 avatar Mar 10 '25 11:03 terry8204

I switched to version 6.0-d4 and the issue was not present. [2025-02-28 09:47:57.841][ERROR][5969][406y4882][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/33920003917_1_0_1078_video is busy thread [5969][406y4882]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:263][errno=11] thread [5969][406y4882]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:457][errno=11] thread [5969][406y4882]: acquire_publish() [./src/app/srs_app_rtmp_conn.cpp:1078][errno=11](Resource temporarily unavailable) [2025-02-28 09:47:58.168][ERROR][5969][0129i879][11] serve error code=1028(StreamBusy)(Stream already exists or busy) : service cycle : rtmp: stream service : rtmp: stream /live/33920003917_3_0_1078_video is busy thread [5969][0129i879]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:263][errno=11] thread [5969][0129i879]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:457][errno=11] thread [5969][0129i879]: acquire_publish() [./src/app/srs_app_rtmp_conn.cpp:1078][errno=11](Resource temporarily unavailable)

TRANS_BY_GPT4

terry8204 avatar Mar 10 '25 11:03 terry8204

Should have been fixed in latest versions.

winlinvip avatar Oct 26 '25 14:10 winlinvip