From 2b76b620b92c15e41fbb5677a326a90f0f365c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 16 Jan 2019 19:26:23 +0100 Subject: [PATCH] Fix worker 100% CPU usage due to wrong iteration in Router.cpp destructor --- worker/include/RTC/Transport.hpp | 3 --- worker/src/RTC/Router.cpp | 19 ++++++++----------- worker/src/RTC/Transport.cpp | 13 ------------- worker/src/RTC/WebRtcTransport.cpp | 6 ------ 4 files changed, 8 insertions(+), 33 deletions(-) diff --git a/worker/include/RTC/Transport.hpp b/worker/include/RTC/Transport.hpp index ed7b4c8dca..9b0b3f898b 100644 --- a/worker/include/RTC/Transport.hpp +++ b/worker/include/RTC/Transport.hpp @@ -68,7 +68,6 @@ namespace RTC virtual ~Transport(); public: - void Close(); virtual Json::Value ToJson() const = 0; virtual Json::Value GetStats() const = 0; void HandleProducer(RTC::Producer* producer); @@ -129,8 +128,6 @@ namespace RTC Timer* rtcpTimer{ nullptr }; RTC::UdpSocket* mirrorSocket{ nullptr }; RTC::TransportTuple* mirrorTuple{ nullptr }; - // Others. - bool closed{ false }; // Others (Producers and Consumers). std::unordered_set producers; std::unordered_set consumers; diff --git a/worker/src/RTC/Router.cpp b/worker/src/RTC/Router.cpp index b9472fe088..13649e2532 100644 --- a/worker/src/RTC/Router.cpp +++ b/worker/src/RTC/Router.cpp @@ -59,9 +59,8 @@ namespace RTC { auto* transport = it->second; - // Do not delete the Transport but call to its Close() method so it will call us - // on OnTransportClosed() and will delete it there. - transport->Close(); + it = this->transports.erase(it); + delete transport; } // Close the audio level timer. @@ -595,12 +594,10 @@ namespace RTC return; } - // Do not delete the Transport but call to its Close() method so it will call us - // on OnTransportClosed() and will delete it there. - transport->Close(); - MS_DEBUG_DEV("Transport closed [transportId:%" PRIu32 "]", transport->transportId); + delete transport; + request->Accept(); break; @@ -995,10 +992,10 @@ namespace RTC return; } - delete producer; - MS_DEBUG_DEV("Producer closed [producerId:%" PRIu32 "]", producer->producerId); + delete producer; + request->Accept(); break; @@ -1167,6 +1164,8 @@ namespace RTC return; } + MS_DEBUG_DEV("Consumer closed [consumerId:%" PRIu32 "]", consumer->consumerId); + delete consumer; request->Accept(); @@ -1598,8 +1597,6 @@ namespace RTC MS_TRACE(); this->transports.erase(transport->transportId); - - delete transport; } void Router::OnProducerClosed(RTC::Producer* producer) diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index 39f0524dfb..e2a9a40094 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -34,19 +34,6 @@ namespace RTC { MS_TRACE(); - if (!this->closed) - Close(); - } - - void Transport::Close() - { - MS_TRACE(); - - if (this->closed) - return; - - this->closed = true; - // Close all the handled Producers. for (auto it = this->producers.begin(); it != this->producers.end();) { diff --git a/worker/src/RTC/WebRtcTransport.cpp b/worker/src/RTC/WebRtcTransport.cpp index d3960e52b6..d3d6014c64 100644 --- a/worker/src/RTC/WebRtcTransport.cpp +++ b/worker/src/RTC/WebRtcTransport.cpp @@ -1181,9 +1181,6 @@ namespace RTC // Notify. eventData[JsonStringDtlsState] = JsonStringFailed; this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); - - // This is a fatal error so close the transport. - Close(); } void WebRtcTransport::OnDtlsClosed(const RTC::DtlsTransport* /*dtlsTransport*/) @@ -1200,9 +1197,6 @@ namespace RTC // Notify. eventData[JsonStringDtlsState] = JsonStringClosed; this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); - - // This is a fatal error so close the transport. - Close(); } void WebRtcTransport::OnOutgoingDtlsData(