From 0dd6c31487c2d4adc163d0b136d3c5976c7e2a7d Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 21 Mar 2020 22:41:25 +0800 Subject: [PATCH] Fix #1629, fix kickoff FLV client bug. 3.0.137 --- README.md | 2 ++ trunk/src/app/srs_app_http_conn.cpp | 38 ++++++++++++++++++++------- trunk/src/app/srs_app_http_conn.hpp | 3 +++ trunk/src/app/srs_app_http_stream.cpp | 12 ++++----- trunk/src/core/srs_core_version3.hpp | 2 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f25438e0a..e7b88dcbf 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-21, For [#1629][bug #1629], fix kickoff FLV client bug. 3.0.137 * v3.0, 2020-03-21, For [#1619][bug #1619], configure without utest by default. 3.0.136 * v3.0, 2020-03-21, For [#1651][bug #1651], fix return pnwrite of srs_write_large_iovs. 3.0.135 * v3.0, 2020-03-18, [3.0 beta3(3.0.134)][r3.0b3] released. 122509 lines. @@ -1680,6 +1681,7 @@ Winlin [bug #1635]: https://github.com/ossrs/srs/issues/1635 [bug #1651]: https://github.com/ossrs/srs/issues/1651 [bug #1619]: https://github.com/ossrs/srs/issues/1619 +[bug #1629]: https://github.com/ossrs/srs/issues/1629 [bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index fc1831aa4..8f9429cbc 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -198,19 +198,32 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq) srs_error_t err = srs_success; SrsStSocket skt; - + if ((err = skt.initialize(stfd)) != srs_success) { return srs_error_wrap(err, "init socket"); } - - if ((err = parser->parse_message(&skt, preq)) != srs_success) { - return srs_error_wrap(err, "parse message"); + + // Check user interrupt by interval. + skt.set_recv_timeout(3 * SRS_UTIME_SECONDS); + + // drop all request body. + char body[4096]; + while (true) { + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "timeout"); + } + + if ((err = skt.read(body, 4096, NULL)) != srs_success) { + // Because we use timeout to check trd state, so we should ignore any timeout. + if (srs_error_code(err) == ERROR_SOCKET_TIMEOUT) { + srs_freep(err); + continue; + } + + return srs_error_wrap(err, "read response"); + } } - // Attach owner connection to message. - SrsHttpMessage* hreq = (SrsHttpMessage*)(*preq); - hreq->set_connection(this); - return err; } @@ -219,12 +232,12 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) srs_error_t err = srs_success; ISrsHttpResponseReader* br = msg->body_reader(); - + // when not specified the content length, ignore. if (msg->content_length() == -1) { return err; } - + // drop all request body. char body[4096]; while (!br->eof()) { @@ -236,6 +249,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg) return err; } +void SrsResponseOnlyHttpConn::expire() +{ + SrsHttpConn::expire(); +} + SrsHttpServer::SrsHttpServer(SrsServer* svr) { server = svr; diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index f3de6659e..7529cfc5b 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -101,6 +101,9 @@ public: virtual srs_error_t pop_message(ISrsHttpMessage** preq); public: virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg); +public: + // Set connection to expired. + virtual void expire(); }; // The http server, use http stream or static server to serve requests. diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index fb7bd54b3..815561e1e 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -592,10 +592,15 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess SrsAutoFree(SrsPithyPrint, pprint); SrsMessageArray msgs(SRS_PERF_MW_MSGS); + + // Use receive thread to accept the close event to avoid FD leak. + // @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427 + SrsHttpMessage* hr = dynamic_cast(r); + SrsResponseOnlyHttpConn* hc = dynamic_cast(hr->connection()); // update the statistic when source disconveried. SrsStatistic* stat = SrsStatistic::instance(); - if ((err = stat->on_client(_srs_context->get_id(), req, NULL, SrsRtmpConnPlay)) != srs_success) { + if ((err = stat->on_client(_srs_context->get_id(), req, hc, SrsRtmpConnPlay)) != srs_success) { return srs_error_wrap(err, "stat on client"); } @@ -613,11 +618,6 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess } SrsFlvStreamEncoder* ffe = dynamic_cast(enc); - - // Use receive thread to accept the close event to avoid FD leak. - // @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427 - SrsHttpMessage* hr = dynamic_cast(r); - SrsResponseOnlyHttpConn* hc = dynamic_cast(hr->connection()); // Set the socket options for transport. bool tcp_nodelay = _srs_config->get_tcp_nodelay(req->vhost); diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index e6022c5df..95a9c694d 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 136 +#define SRS_VERSION3_REVISION 137 #endif