Skip to content

Commit

Permalink
Fix worker 100% CPU usage due to wrong iteration in Router.cpp destru…
Browse files Browse the repository at this point in the history
…ctor
  • Loading branch information
ibc committed Jan 16, 2019
1 parent d4854d9 commit 2b76b62
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 33 deletions.
3 changes: 0 additions & 3 deletions worker/include/RTC/Transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<RTC::Producer*> producers;
std::unordered_set<RTC::Consumer*> consumers;
Expand Down
19 changes: 8 additions & 11 deletions worker/src/RTC/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -995,10 +992,10 @@ namespace RTC
return;
}

delete producer;

MS_DEBUG_DEV("Producer closed [producerId:%" PRIu32 "]", producer->producerId);

delete producer;

request->Accept();

break;
Expand Down Expand Up @@ -1167,6 +1164,8 @@ namespace RTC
return;
}

MS_DEBUG_DEV("Consumer closed [consumerId:%" PRIu32 "]", consumer->consumerId);

delete consumer;

request->Accept();
Expand Down Expand Up @@ -1598,8 +1597,6 @@ namespace RTC
MS_TRACE();

this->transports.erase(transport->transportId);

delete transport;
}

void Router::OnProducerClosed(RTC::Producer* producer)
Expand Down
13 changes: 0 additions & 13 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();)
{
Expand Down
6 changes: 0 additions & 6 deletions worker/src/RTC/WebRtcTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/)
Expand All @@ -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(
Expand Down

0 comments on commit 2b76b62

Please sign in to comment.