-
-
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
Make static variables in worker be in thread-local storage #523
Conversation
What does this mean and why do we need this? |
Definitely this must be fixed in usrsctp side. Said that, since mediasoup-worker is still a separate process I assume we don't have any issue even if we merge this, right? However, I don't understand yet the purpose of this "ability to run worker in a thread instead of own whole process". Definitely mediasoup-worker is designed to be a separate process, no matter it is a single thread process or not. |
Right, this is related to my work on librarifying mediasoup-worker (as I mentioned on the forum), which is to be able to wrap it into Rust library and be able to install as a dependency with Rust port automatically instead of requiring to build manually and specify path to manually, just as seamless as it works with Node.js. Building executable as part of the dependency installation in this case would be weird for Rust library and confusing in case of building static binaries, etc. Worker works in a thread in my fork already as soon as there is just one worker per app, but ideally it should be possible to create more than 1 worker, for which I need each worker to be isolated within its thread and not use global state (making worker multi-thread aware is, obviously, out of consideration here). Here is a quite from another PR:
The concern here is that if one of 3 callbacks currently set in the code are called from that "SCTP iterator" thread, then thread-local variables will not be accessible and things will fail. I do not know whether it is the case, I'll probably raise a question in usrsctp repo to clarify that. |
This clearly doesn't work, closing for now |
Why do you say that it doesn't work? |
First of all, more things need to be made thread-local, which I did in my fork for testing. Second, in concurrent execution with multiple workers in different threads I still get weird SCTP-related segfaults that I don't quite understand the origin of (call site is protected by lock in usrsctp, yet it fails), something like this:
If someone could help me with that, that would be awsome, but lack of any documentation on those methods from usrsctp and tons of conditionally compiled code makes it basically undebuggable for me. |
I see. Problem here is:
|
Yeah, I saw those. And considering this is not something that is of any priority for you, I'll have to figure it out on my own it seems. Will post on the forum any updates I have. Will submit another PR if I find a way to make it work, but in this form it is not useful for anyone. |
More than priority it's more about we don't find confident at all to solve such an internal hell in usrsctp... |
This is another necessary change towards ability to run worker in a thread instead of own whole process.
Tests pass, but I'm a bit worried about "SCTP iterator" thread that is still being created, see sctplab/usrsctp#472