-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DepUsrSCTP::Checker::timer not being freed #576
Conversation
OHHHHH the problem in tests is that Fixing here and in v3. @jmillan cough cough |
Sorry, I was testing in v3... I should go to bed |
It actually happens with Node tests as well, you just don't see it due to the way Node API works. |
I used this for testing: diff --git a/worker/src/DepLibUV.cpp b/worker/src/DepLibUV.cpp
--- a/worker/src/DepLibUV.cpp (revision 45729a4f3a1cfcbca2ead52362115d7f6467ad92)
+++ b/worker/src/DepLibUV.cpp (date 1622587923886)
@@ -4,11 +4,28 @@
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include <cstdlib> // std::abort()
+#include <iostream>
+#include <fstream>
+
+using std::cout; using std::ofstream;
+using std::endl; using std::string;
+using std::cerr;
+using std::fstream;
/* Static variables. */
thread_local uv_loop_t* DepLibUV::loop{ nullptr };
+void on_uv_walk(uv_handle_t* handle, void* arg)
+{
+ string filename("output.txt");
+ fstream output_fstream;
+
+ output_fstream.open(filename, std::ios_base::out);
+
+ output_fstream << "Maecenas accumsan purus id \norci gravida pellentesque." << endl;
+}
+
/* Static methods. */
void DepLibUV::ClassInit()
@@ -27,10 +44,28 @@
{
MS_TRACE();
- // This should never happen.
if (DepLibUV::loop != nullptr)
{
- uv_loop_close(DepLibUV::loop);
+ int err;
+
+ uv_stop(DepLibUV::loop);
+ uv_walk(DepLibUV::loop, on_uv_walk, NULL);
+
+ while (true)
+ {
+ err = uv_loop_close(DepLibUV::loop);
+
+ if (err != UV_EBUSY)
+ {
+ break;
+ }
+
+ uv_run(DepLibUV::loop, UV_RUN_NOWAIT);
+ }
+
+ if (err != 0)
+ MS_ABORT("failed to close libuv loop: %s", uv_err_name(err));
+
delete DepLibUV::loop;
}
} After running node tests you'll see |
I'll do more tomorrow. Could you please print (into file) |
Ok, I've done. BTW use
There is some culprit here. BTW: uv handles have a |
Culprit is somewhere in |
Also, if I comment If I do not comment those lines, the file has 16 lines. Which proves that this is the only bug that really affects mediasoup (the other 15 are just in worker tests). |
I see what the problem is:
Solutions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on my end with valgrind, looks good!
Ok, I get this in the worker tests: And it makes sense because we have to fix the tests. I'll change the abort with a error log. |
The remaining open handle in the tests happens for the Timer of NackGenerator, in the following test: SECTION("require key frame")
{
RtpStreamRecvListener listener;
RtpStreamRecv rtpStream(&listener, params);
packet->SetSequenceNumber(1);
rtpStream.ReceivePacket(packet);
// Seq different is bigger than MaxNackPackets in NackGenerator, so it
// triggers a key frame.
packet->SetSequenceNumber(1003);
listener.shouldTriggerPLI = true;
listener.shouldTriggerFIR = false;
rtpStream.ReceivePacket(packet);
} It reproduces by simly creating a RtpStreamRecv instance: SECTION("require key frame")
{
RtpStreamRecvListener listener;
RtpStreamRecv rtpStream(&listener, params);
} The following logs gives a glimpse of what's going on: NackGenerator::NackGenerator
NackGenerator::~NackGenerator
Timer::Close()
type: 13, active: 0, closing: 1, has_ref :1
Timer onClose() The Timer static |
Of course, this is how libuv works, but we are doing it wrong here by not runnning |
@jmillan running Do you know where else the remaining 6 may be? I mean: they must be classes that create a Timer inside. |
@jmillan @nazar-pc I've pushed a commit to always check uv_walk (this is, whether there is open handles) and print errors if so. As told in my previous comment, there are 6 remaining issues in worker tests. It can be shown (in this branch) by running test as follows (in
Output:
|
EVERYTHING FIXED |
Released in mediasoup 3.7.11 |
UPDATE: THIS PR IS NOW READY TO BE MERGED
Rationale and solution below in this comment.
Related to PR #575.
THIS PR IS NOT INTENDED TO BE MERGED AT ALL
I've added this in
DepLibUV.cpp
:What I see:
In mediasoup Node tests,
onWalk()
is never called (this is good and expected/desired behavior).When running mediasoup in a real application (example, mediasoup-demo), if I call
worker.close()
in Node, neither I see any call toonWalk()
(this is good and expected/desired behavior).However, when running the mediasoup-worker tests (this is:
make test -C worker
) I see this output:Note that
handle->type
13 meansUV_TIMER
: http://docs.libuv.org/en/v1.x/handle.html?highlight=uv_handle_type#c.uv_handle_typeAnd this seems to be because, in worker tests, we initiate (maybe among others) some
KeyFrameRequestManager
instances (although the problem may be somewhere else) and it may happen that we are not closing some of them properly so they remain active.So what I mean is that, AFAIS, the only issue I see in in
mediasoup/worker/tests/
.