Soft deadlock between pjsua_get_call_info and ios_stream_stop on iOS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

I believe I came across an issue that causes a soft deadlock between
pjsua_get_call_info and ios_stream_stop when hanging up a video call
and grabbing the call information in the on_call_state callback. At
least on my machines this is very reproducible as it happens 9 times
out of 10.

PJSIP is compiled with FFMPEG and x264. When ending a call, the code
in pjsua_call.c pjsua_call_on_state_changed() triggers which at one
point calls the on_call_state callback.

Afterwards, in the same file, it PJSUA_LOCK()s the mutex and calls
pjsua_media_channel_deinit(). A couple of levels deep this finally
gets to the ios_stream_stop() function which attempts to switch to the
main thread so it can end the AVCaptureSession:

if ([NSThread isMainThread]) {
[stream->cap_session stopRunning];
} else {
dispatch_sync(dispatch_get_main_queue(), ^{ [stream->cap_session
stopRunning]; }); }

Now, if the callback code passes that message on using a dispatch_* or
another method and executes moments later and attempts to get the call
information, pjsua_call_get_info() will attempt to PJSUA_LOCK() as
well, which will fail and start waiting for the mutex to unlock. At
the same time, the ios_stream_stop() dispatch_sync tries to execute,
but because of the pending pjsua_call_get_info() mutex it never
actually gets a chance to and therefore the mutex initially locked by
pjsua_media_channel_deinit() is never unlocked.

To make matters worse, I also have a periodical pjsua_call_get_info()
call that triggers every second on the main thread, so that probably
helps with making the issue more reproducible.

I'm trying to find a solution for this that doesn't involve moving the
pjsua_call_get_info() to a whole new thread, but so far I've come
short. Can anyone offer me a suggestion?

Thanks



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux