diff --git a/README.md b/README.md index ae034b22d..123a1b39b 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-12, For [#1634][bug #1634], always check status in thread loop. 3.0.126 * v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125 * v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 * v3.0, 2020-03-05, [3.0 beta2(3.0.123)][r3.0b2] released. 122170 lines. diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 8a0592dcf..8c057af51 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -234,15 +234,17 @@ srs_error_t SrsEdgeIngester::cycle() srs_error_t err = srs_success; while (true) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "edge ingester"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("EdgeIngester: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "edge ingester"); - } - + srs_usleep(SRS_EDGE_INGESTER_CIMS); } @@ -314,7 +316,6 @@ srs_error_t SrsEdgeIngester::ingest(string& redirect) redirect = ""; while (true) { - srs_error_t err = srs_success; if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "thread quit"); } @@ -534,14 +535,16 @@ srs_error_t SrsEdgeForwarder::cycle() srs_error_t err = srs_success; while (true) { - if ((err = do_cycle()) != srs_success) { - return srs_error_wrap(err, "do cycle"); - } - + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "thread pull"); } - + + if ((err = do_cycle()) != srs_success) { + return srs_error_wrap(err, "do cycle"); + } + srs_usleep(SRS_EDGE_FORWARDER_CIMS); } diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 339d12bde..882d33a8c 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -181,15 +181,17 @@ srs_error_t SrsForwarder::cycle() srs_error_t err = srs_success; while (true) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "forwarder"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("Forwarder: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "forwarder"); - } - + srs_usleep(SRS_FORWARDER_CIMS); } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 7a0688fff..fb7bd54b3 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -646,13 +646,13 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess // TODO: free and erase the disabled entry after all related connections is closed. // TODO: FXIME: Support timeout for player, quit infinite-loop. while (entry->enabled) { - pprint->elapse(); - // Whether client closed the FD. if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "recv thread"); } + pprint->elapse(); + // get messages from consumer. // each msg in msgs.msgs must be free, for the SrsMessageArray never free them. int count = 0; diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index addbd9bc2..44987f16c 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -201,15 +201,17 @@ srs_error_t SrsIngester::cycle() srs_error_t err = srs_success; while (!disposed) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "ingester"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("Ingester: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "ingester"); - } - + srs_usleep(SRS_AUTO_INGESTER_CIMS); } diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index 18d719e78..30ebc5ecb 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -83,16 +83,18 @@ srs_error_t SrsNgExec::cycle() srs_error_t err = srs_success; while (true) { - if ((err = do_cycle()) != srs_success) { - srs_warn("EXEC: Ignore error, %s", srs_error_desc(err).c_str()); - srs_freep(err); - } - + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 if ((err = trd->pull()) != srs_success) { err = srs_error_wrap(err, "ng exec cycle"); break; } - + + if ((err = do_cycle()) != srs_success) { + srs_warn("EXEC: Ignore error, %s", srs_error_desc(err).c_str()); + srs_freep(err); + } + srs_usleep(SRS_RTMP_EXEC_CIMS); } diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 98bfcd5fc..c7e943337 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -381,7 +381,6 @@ srs_error_t SrsRtmpConn::service_cycle() } while (true) { - srs_error_t err = srs_success; if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } @@ -704,14 +703,14 @@ srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, Sr srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_enabled, realtime, tcp_nodelay); while (true) { - // collect elapse for pithy print. - pprint->elapse(); - // when source is set to expired, disconnect it. if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } - + + // collect elapse for pithy print. + pprint->elapse(); + // to use isolate thread to recv, can improve about 33% performance. // @see: https://github.com/ossrs/srs/issues/196 // @see: https://github.com/ossrs/srs/issues/217 @@ -872,12 +871,12 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* int64_t nb_msgs = 0; uint64_t nb_frames = 0; while (true) { - pprint->elapse(); - if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } - + + pprint->elapse(); + // cond wait for timeout. if (nb_msgs == 0) { // when not got msgs, wait for a larger timeout. diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 8a69c55d2..acedd7db1 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 125 +#define SRS_VERSION3_REVISION 126 #endif