-
-
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 usrsctp usage in Rust #1353
base: v3
Are you sure you want to change the base?
Conversation
**WIP** Fixes #1352 ### Details - Basically as described in the ticket. But not everything is done at all. - Also, I'm testing this in Node by using UV async stuff (which doesn't make sense in mediasoup for Node but anyway). ### TODO - None of these changes should take effect when in Node, so we need to pass (or to NOT pass) some `define` only from Rust to enable this in the C++ code. We don't want to deal with UV async stuff when in Node because it's not needed at all, so let's see how to do it. - Missing thread X to initialize usrsctp and run the `Checker` singleton. And many other things. - Crash when a `SctpAssociation` is closed. I think it's because somehow the `onAsync` callback is invoked asynchronously (of course) so when it calls `sctpAssociation->OnUsrSctpSendSctpData()` it happens that such a `SctpAssociation` has already been freed. Not sure how to resolve it. Here the logs: ``` mediasoup:Transport close() +18s mediasoup:Channel request() [method:ROUTER_CLOSE_TRANSPORT] +8s mediasoup:Producer transportClosed() +19s mediasoup:DataProducer transportClosed() +18s mediasoup:DataProducer transportClosed() +0ms mediasoup:Transport close() +1ms mediasoup:Channel request() [method:ROUTER_CLOSE_TRANSPORT] +1ms mediasoup:Consumer transportClosed() +19s mediasoup:DataConsumer transportClosed() +18s mediasoup:DataConsumer transportClosed() +1ms mediasoup:Channel [pid:98040] RTC::SctpAssociation::ResetSctpStream() | SCTP_RESET_STREAMS sent [streamId:1] +1ms mediasoup:Channel request succeeded [method:ROUTER_CLOSE_TRANSPORT, id:39] +0ms DepUsrSCTP::onAsync() | ---------- onAsync!! DepUsrSCTP::onAsync() | ---------- onAsync, sending SCTP data!! mediasoup:Channel Producer Channel ended by the worker process +1ms mediasoup:ERROR:Worker worker process died unexpectedly [pid:98040, code:null, signal:SIGSEGV] +0ms ```
Issue 1: test-node-sctp.ts failsI've added some console logs: 069f78e The test fails because first sent message is not later received by the data consumer:
UPDATE: Issue found. Problem is that when usrsctp send callback is called, there we store sending data into a map and then invoke uv async (which will happen time later) and such a uv async will read from that storage to send the data. Problem is that, if two sequential messages must be sent to a peer, the second one will override the first one in the storage so when uv async callback is executed it will only read the second one. Here the issue (see how
Solution is: Store all pending messages to be sent in a container. |
Maybe related to this?: https://docs.libuv.org/en/v1.x/async.html
|
… sent in async cb
Ok, so I've solved the problem as follows: 1a25bed Test now works (for simplicity is temporary reduced to just 2 messages) and all logs are good:
|
And OF COURSE a double free bug that just happens in Rust in CI in Ubuntu and not in MacOS, to make me spend yet another 2 extra days on this: https://github.com/versatica/mediasoup/actions/runs/8172985292/job/22344414084?pr=1353 |
Are you making sure that threadA is not writing to a |
ClassDestroy() method should also use the mutex since it clears the storage map so every store is deallocated so it deletes all items in the items array. It maybe that. |
Also take into account that this PR doesn't yet implement the thing about running the Checker in a separate thread. |
No, false alarm, it already calls |
…the Worker is closed) and more things Also make checker static rather than thread_local static. Remove many debugging logs and stuff. TODO: Rust tests do not finish.
I've done many changes in ca5f222:
|
Issue 2When running any test in Node: npx jest --testPathPattern node/src/test/test-node-sctp.ts
This is because
As you can see, when |
After a meeting with Jose we have decided that, as originally planned, the timer of the usrsctp |
Running a test with ThreadSanitizer enabled may help confirm that. |
WIP
Fixes #1352
Details
TODO
None of these changes should take effect when in Node, so we need to pass (or to NOT pass) some
define
only from Rust to enable this in the C++ code. We don't want to deal with UV async stuff when in Node because it's not needed at all, so let's see how to do it.Missing thread X to initialize usrsctp and run the
Checker
singleton. And many other things.