Unverified 提交 3b8c06ed authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi 提交者: GitHub

Fix memory leaks on error exit, minor tweaks (#581)

* Fix memory leaks in case worker exits with error

* Skip delay on shutdown in library mode

* Unlock SCTP cleanup, it no longer causes issues

* Remove output from build cache to fix CI
上级 070643c7
...@@ -32,8 +32,6 @@ jobs: ...@@ -32,8 +32,6 @@ jobs:
with: with:
path: | path: |
~/.npm ~/.npm
worker/deps
worker/out
key: ${{ matrix.os }}-node-${{ hashFiles('**/package.json') }} key: ${{ matrix.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: | restore-keys: |
${{ matrix.os }}-node- ${{ matrix.os }}-node-
......
...@@ -61,8 +61,6 @@ jobs: ...@@ -61,8 +61,6 @@ jobs:
with: with:
path: | path: |
~/.npm ~/.npm
worker/deps
worker/out
key: ${{ matrix.build.os }}-node-${{matrix.build.cc}}-${{ hashFiles('**/package.json') }} key: ${{ matrix.build.os }}-node-${{matrix.build.cc}}-${{ hashFiles('**/package.json') }}
restore-keys: | restore-keys: |
${{ matrix.build.os }}-node-${{matrix.build.cc}}- ${{ matrix.build.os }}-node-${{matrix.build.cc}}-
......
...@@ -20,8 +20,8 @@ inline static void onWalk(uv_handle_t* handle, void* arg) ...@@ -20,8 +20,8 @@ inline static void onWalk(uv_handle_t* handle, void* arg)
{ {
// Must use MS_ERROR_STD since at this point the Channel is already closed. // Must use MS_ERROR_STD since at this point the Channel is already closed.
MS_ERROR_STD( MS_ERROR_STD(
"alive UV handle found (this shouldn't happen) [type:%d, active:%d, closing:%d, has_ref:%d]", "alive UV handle found (this shouldn't happen) [type:%s, active:%d, closing:%d, has_ref:%d]",
handle->type, uv_handle_type_name(handle->type),
uv_is_active(handle), uv_is_active(handle),
uv_is_closing(handle), uv_is_closing(handle),
uv_has_ref(handle)); uv_has_ref(handle));
......
...@@ -96,12 +96,10 @@ void DepUsrSCTP::ClassDestroy() ...@@ -96,12 +96,10 @@ void DepUsrSCTP::ClassDestroy()
{ {
usrsctp_finish(); usrsctp_finish();
// TODO: This cleanup currently causes assertion errors in numSctpAssociations = 0u;
// DepUsrSCTP::DeregisterSctpAssociation() when using mediasoup-worker nextSctpAssociationId = 0u;
// in thread mode (Rust).
// DepUsrSCTP::mapIdSctpAssociation.clear();
// numSctpAssociations = 0u; nextSctpAssociationId = 0u;
// DepUsrSCTP::mapIdSctpAssociation.clear();
} }
} }
} }
......
...@@ -48,12 +48,6 @@ Worker::~Worker() ...@@ -48,12 +48,6 @@ Worker::~Worker()
{ {
MS_TRACE(); MS_TRACE();
// Delete the Channel.
delete this->channel;
// Delete the PayloadChannel.
delete this->payloadChannel;
if (!this->closed) if (!this->closed)
Close(); Close();
} }
......
...@@ -40,37 +40,44 @@ extern "C" int run_worker( ...@@ -40,37 +40,44 @@ extern "C" int run_worker(
// Initialize libuv stuff (we need it for the Channel). // Initialize libuv stuff (we need it for the Channel).
DepLibUV::ClassInit(); DepLibUV::ClassInit();
// Channel socket (it will be handled and deleted by the Worker). // Channel socket.
Channel::ChannelSocket* channel{ nullptr }; std::unique_ptr<Channel::ChannelSocket> channel{ nullptr };
// PayloadChannel socket (it will be handled and deleted by the Worker). // PayloadChannel socket.
PayloadChannel::PayloadChannelSocket* payloadChannel{ nullptr }; std::unique_ptr<PayloadChannel::PayloadChannelSocket> payloadChannel{ nullptr };
try try
{ {
channel = new Channel::ChannelSocket(consumerChannelFd, producerChannelFd); channel.reset(new Channel::ChannelSocket(consumerChannelFd, producerChannelFd));
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
MS_ERROR_STD("error creating the Channel: %s", error.what()); MS_ERROR_STD("error creating the Channel: %s", error.what());
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();
return 1; return 1;
} }
try try
{ {
payloadChannel = payloadChannel.reset(
new PayloadChannel::PayloadChannelSocket(payloadConsumeChannelFd, payloadProduceChannelFd); new PayloadChannel::PayloadChannelSocket(payloadConsumeChannelFd, payloadProduceChannelFd));
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
MS_ERROR_STD("error creating the RTC Channel: %s", error.what()); MS_ERROR_STD("error creating the RTC Channel: %s", error.what());
channel->Close();
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();
return 1; return 1;
} }
// Initialize the Logger. // Initialize the Logger.
Logger::ClassInit(channel); Logger::ClassInit(channel.get());
try try
{ {
...@@ -80,6 +87,11 @@ extern "C" int run_worker( ...@@ -80,6 +87,11 @@ extern "C" int run_worker(
{ {
MS_ERROR_STD("settings error: %s", error.what()); MS_ERROR_STD("settings error: %s", error.what());
channel->Close();
payloadChannel->Close();
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();
// 42 is a custom exit code to notify "settings error" to the Node library. // 42 is a custom exit code to notify "settings error" to the Node library.
return 42; return 42;
} }
...@@ -87,6 +99,11 @@ extern "C" int run_worker( ...@@ -87,6 +99,11 @@ extern "C" int run_worker(
{ {
MS_ERROR_STD("unexpected settings error: %s", error.what()); MS_ERROR_STD("unexpected settings error: %s", error.what());
channel->Close();
payloadChannel->Close();
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();
return 1; return 1;
} }
...@@ -121,18 +138,16 @@ extern "C" int run_worker( ...@@ -121,18 +138,16 @@ extern "C" int run_worker(
Utils::Crypto::ClassInit(); Utils::Crypto::ClassInit();
RTC::DtlsTransport::ClassInit(); RTC::DtlsTransport::ClassInit();
RTC::SrtpSession::ClassInit(); RTC::SrtpSession::ClassInit();
Channel::ChannelNotifier::ClassInit(channel); Channel::ChannelNotifier::ClassInit(channel.get());
PayloadChannel::PayloadChannelNotifier::ClassInit(payloadChannel); PayloadChannel::PayloadChannelNotifier::ClassInit(payloadChannel.get());
#ifdef MS_EXECUTABLE #ifdef MS_EXECUTABLE
{ // Ignore some signals.
// Ignore some signals. IgnoreSignals();
IgnoreSignals();
}
#endif #endif
// Run the Worker. // Run the Worker.
Worker worker(channel, payloadChannel); Worker worker(channel.get(), payloadChannel.get());
// Free static stuff. // Free static stuff.
DepLibSRTP::ClassDestroy(); DepLibSRTP::ClassDestroy();
...@@ -142,9 +157,11 @@ extern "C" int run_worker( ...@@ -142,9 +157,11 @@ extern "C" int run_worker(
DepUsrSCTP::ClassDestroy(); DepUsrSCTP::ClassDestroy();
DepLibUV::ClassDestroy(); DepLibUV::ClassDestroy();
#ifdef MS_EXECUTABLE
// Wait a bit so pending messages to stdout/Channel arrive to the Node // Wait a bit so pending messages to stdout/Channel arrive to the Node
// process. // process.
uv_sleep(200); uv_sleep(200);
#endif
return 0; return 0;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论