Need help in a segmentation fault I'm facing when closing Producers.

First of all, thank you for this great library.

I’m using it for a live streaming use case, and I’ve come across some segmentation faults during certain flows.
In my setup:

  • First, I create the send transport.
  • Then, I create producers on that transport.
  • While closing, I first close all producers, then close the send transport.

The app crashes with a segmentation fault with the following stack trace:

#00 pc ... libmediasoup_client.so (mediasoupclient::Producer::Close()+188)
#01 pc ... libmediasoup_client.so (mediasoupclient::Producer::privateListener->OnClose()) 
#02 pc ... libmediasoup_client.so
#03 pc ... Java_com_demo_video_component_AndroidProducer_nativeClose+168
...

For now, After closing all producers, Im adding a 1 second delay before closing send transport. that way the privateListener might not be pointing to null.

Also, I noticed there are several places in the code marked with comments like // This may throw. In some cases, these actually lead to crashes.

So my question is:
What’s the right way to handle situations like this?

Should our app never reach that crash path — meaning it’s a bug (some wrong handling) if it does?

— Or should we add extra safety checks in the mediasoup code (as a patch file on top) and throw a proper exception instead, so we can catch it instead of crashing with a segmentation fault?

I’d guess it’s race conditions, you’d need to google and find examples to best understand your direction to fix this.

Checks should be in place to prevent system going out of synchronization (state stays truthful). Queues are applied sometimes but careful to not block the chain of cmds/messages. You can run exceptions to better know why an error throws and improve.

Okay, will revisit my synchronisation locks across mediasoup ops and check if Im missing somethings. thanks