Skip to content

Commit ad0d510

Browse files
winlinvipsuzp1984
andcommitted
Edge: Improve stability for state and fd closing. v5.0.214 (#4126)
1. Should always stop coroutine before close fd, see #511, #1784 2. When edge forwarder coroutine quit, always set the error code. 3. Do not unpublish if invalid state. --------- Co-authored-by: Jacob Su <[email protected]>
1 parent 3139137 commit ad0d510

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

trunk/doc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v5-changes"></a>
88

99
## SRS 5.0 Changelog
10+
* v5.0, 2024-07-24, Merge [#4126](https://github.com/ossrs/srs/pull/4126): Edge: Improve stability for state and fd closing. v5.0.214 (#4126)
1011
* v5.0, 2024-06-03, Merge [#4057](https://github.com/ossrs/srs/pull/4057): RTC: Support dropping h.264 SEI from NALUs. v5.0.213 (#4057)
1112
* v5.0, 2024-04-23, Merge [#4038](https://github.com/ossrs/srs/pull/4038): RTMP: Do not response publish start message if hooks fail. v5.0.212 (#4038)
1213
* v5.0, 2024-04-22, Merge [#4033](https://github.com/ossrs/srs/pull/4033): issue #3967: support x509 certification chiain in single pem file. v5.0.211 (#4033)

trunk/src/app/srs_app_edge.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ srs_error_t SrsEdgeForwarder::start()
780780

781781
url = srs_generate_rtmp_url(server, port, req->host, vhost, req->app, req->stream, req->param);
782782
}
783+
784+
// We must stop the coroutine before disposing the sdk.
785+
srs_freep(trd);
786+
trd = new SrsSTCoroutine("edge-fwr", this, _srs_context->get_id());
783787

784788
// open socket.
785789
srs_freep(sdk);
@@ -804,10 +808,8 @@ srs_error_t SrsEdgeForwarder::start()
804808
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) {
805809
return srs_error_wrap(err, "sdk publish");
806810
}
807-
808-
srs_freep(trd);
809-
trd = new SrsSTCoroutine("edge-fwr", this, _srs_context->get_id());
810-
811+
812+
// Start the forwarding coroutine.
811813
if ((err = trd->start()) != srs_success) {
812814
return srs_error_wrap(err, "coroutine");
813815
}
@@ -819,9 +821,12 @@ srs_error_t SrsEdgeForwarder::start()
819821

820822
void SrsEdgeForwarder::stop()
821823
{
824+
// Make sure the coroutine is stopped before disposing the sdk,
825+
// for sdk is used by coroutine.
822826
trd->stop();
823-
queue->clear();
824827
srs_freep(sdk);
828+
829+
queue->clear();
825830
}
826831

827832
// when error, edge ingester sleep for a while and retry.
@@ -839,6 +844,11 @@ srs_error_t SrsEdgeForwarder::cycle()
839844
}
840845

841846
if ((err = do_cycle()) != srs_success) {
847+
// If cycle stopping, we should always set the quit error code.
848+
if (send_error_code == 0) {
849+
send_error_code = srs_error_code(err);
850+
}
851+
842852
return srs_error_wrap(err, "do cycle");
843853
}
844854

trunk/src/app/srs_app_rtmp_conn.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -946,25 +946,22 @@ srs_error_t SrsRtmpConn::publishing(SrsLiveSource* source)
946946
}
947947

948948
// TODO: FIXME: Should refine the state of publishing.
949-
if ((err = acquire_publish(source)) == srs_success) {
949+
srs_error_t acquire_err = acquire_publish(source);
950+
if ((err = acquire_err) == srs_success) {
950951
// use isolate thread to recv,
951952
// @see: https://github.com/ossrs/srs/issues/237
952953
SrsPublishRecvThread rtrd(rtmp, req, srs_netfd_fileno(stfd), 0, this, source, _srs_context->get_id());
953954
err = do_publishing(source, &rtrd);
954955
rtrd.stop();
955956
}
956957

957-
// whatever the acquire publish, always release publish.
958-
// when the acquire error in the midlle-way, the publish state changed,
959-
// but failed, so we must cleanup it.
960-
// @see https://github.com/ossrs/srs/issues/474
961-
// @remark when stream is busy, should never release it.
962-
if (srs_error_code(err) != ERROR_SYSTEM_STREAM_BUSY) {
958+
// Release and callback when acquire publishing success, if not, we should ignore, because the source
959+
// is not published by this session.
960+
if (acquire_err == srs_success) {
963961
release_publish(source);
962+
http_hooks_on_unpublish();
964963
}
965964

966-
http_hooks_on_unpublish();
967-
968965
return err;
969966
}
970967

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 213
12+
#define VERSION_REVISION 214
1313

1414
#endif

0 commit comments

Comments
 (0)