Index: trunk/pjsip/src/pjsip/sip_transaction.c =================================================================== --- a/pjsip/src/pjsip/sip_transaction.c (revision 5244) +++ b/pjsip/src/pjsip/sip_transaction.c (revision 5572) @@ -1231,5 +1231,27 @@ PJSIP_EVENT_INIT_TSX_STATE(e, tsx, event_src_type, event_src, prev_state); + + /* For timer event, release lock to avoid deadlock. + * This should be safe because: + * 1. The tsx state just switches to TERMINATED or DESTROYED. + * 2. There should be no other processing taking place. All other + * events, such as the ones handled by tsx_on_state_terminated() + * should be ignored. + * 3. tsx_shutdown() hasn't been called. + * Refer to ticket #2001 (https://trac.pjsip.org/repos/ticket/2001). + */ + if (event_src_type == PJSIP_EVENT_TIMER && + (pj_timer_entry *)event_src == &tsx->timeout_timer) + { + pj_grp_lock_release(tsx->grp_lock); + } + (*tsx->tsx_user->on_tsx_state)(tsx, &e); + + if (event_src_type == PJSIP_EVENT_TIMER && + (pj_timer_entry *)event_src == &tsx->timeout_timer) + { + pj_grp_lock_acquire(tsx->grp_lock); + } }