]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix potential deadlock situation in res_pjsip.
authorMark Michelson <mmichelson@digium.com>
Thu, 12 Jun 2014 14:03:52 +0000 (14:03 +0000)
committerMark Michelson <mmichelson@digium.com>
Thu, 12 Jun 2014 14:03:52 +0000 (14:03 +0000)
SIP transaction timeouts are handled in the PJSIP monitor thread. When
this happens on a subscription, and the subscription is destroyed, the
subscription destruction is dispatched synchronously to the threadpool.
The issue is that the PJSIP dialog is locked by the monitor thread,
and then the dispatched task attempts to lock the dialog. This leads
to a deadlock that causes SIP traffic to no longer be accepted on the
Asterisk server.

The fix here is to treat the monitor thread as if it were a threadpool
thread when it attempts to dispatch synchronous tasks. This way, the
dispatched task turns into a simple function call within the same thread,
and the locking issue is averted.

AST-2014-008

ASTERISK-23802 #close

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@415794 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_pjsip.c

index 0fb802ca000925a50d04066c9cea73a35a2ab0cf..08d86537d43fd11aae357a4a091e74d17d5bb2de 100644 (file)
@@ -2194,6 +2194,11 @@ int ast_sip_thread_is_servant(void)
 {
        uint32_t *servant_id;
 
+       if (monitor_thread &&
+                       pthread_self() == *(pthread_t *)pj_thread_get_os_handle(monitor_thread)) {
+               return 1;
+       }
+
        servant_id = ast_threadstorage_get(&servant_id_storage, sizeof(*servant_id));
        if (!servant_id) {
                return 0;