<p>Stanislav Abramenkov has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/20038">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjproject_bundled: Fixed deadlock between SIP transaction and dialog<br><br>ASTERISK-29286<br><br>Change-Id: Iac7972d8e0a4b10db88335dd170d818571fdc814<br>---<br>A third-party/pjproject/patches/0012-Fixed-deadlock-between-SIP-transaction-and-dialog.patch<br>1 file changed, 77 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/38/20038/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/third-party/pjproject/patches/0012-Fixed-deadlock-between-SIP-transaction-and-dialog.patch b/third-party/pjproject/patches/0012-Fixed-deadlock-between-SIP-transaction-and-dialog.patch</span><br><span>new file mode 100644</span><br><span>index 0000000..c4528a9</span><br><span>--- /dev/null</span><br><span>+++ b/third-party/pjproject/patches/0012-Fixed-deadlock-between-SIP-transaction-and-dialog.patch</span><br><span>@@ -0,0 +1,66 @@</span><br><span style="color: hsl(120, 100%, 40%);">+From 0072440c69311bf78f83d00c0ec9566cd9b1e578 Mon Sep 17 00:00:00 2001</span><br><span style="color: hsl(120, 100%, 40%);">+From: sauwming <ming@teluu.com></span><br><span style="color: hsl(120, 100%, 40%);">+Date: Fri, 7 Apr 2023 09:09:45 +0800</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: [PATCH] Different approach: release the lock when calling the</span><br><span style="color: hsl(120, 100%, 40%);">+ callback, without using timer thread</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+---</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip/src/pjsip/sip_transaction.c | 25 +++++++++++++------------</span><br><span style="color: hsl(120, 100%, 40%);">+ 1 file changed, 13 insertions(+), 12 deletions(-)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c</span><br><span style="color: hsl(120, 100%, 40%);">+index d0ed64430..87edf0a04 100644</span><br><span style="color: hsl(120, 100%, 40%);">+--- a/pjsip/src/pjsip/sip_transaction.c</span><br><span>++++ b/pjsip/src/pjsip/sip_transaction.c</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -143,6 +143,7 @@ enum</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+     NO_NOTIFY = 1,</span><br><span style="color: hsl(120, 100%, 40%);">+     NO_SCHEDULE_HANDLER = 2,</span><br><span style="color: hsl(120, 100%, 40%);">++    RELEASE_LOCK = 4</span><br><span style="color: hsl(120, 100%, 40%);">+ };</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Prototypes. */</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -1330,16 +1331,18 @@ static void tsx_set_state( pjsip_transaction *tsx,</span><br><span style="color: hsl(120, 100%, 40%);">+          * 3. tsx_shutdown() hasn't been called.</span><br><span style="color: hsl(120, 100%, 40%);">+          * Refer to ticket #2001 (https://github.com/pjsip/pjproject/issues/2001).</span><br><span style="color: hsl(120, 100%, 40%);">+          */</span><br><span style="color: hsl(120, 100%, 40%);">+-        if (event_src_type == PJSIP_EVENT_TIMER &&</span><br><span style="color: hsl(120, 100%, 40%);">+-            (pj_timer_entry *)event_src == &tsx->timeout_timer)</span><br><span style="color: hsl(120, 100%, 40%);">++        if ((flag & RELEASE_LOCK) != 0 ||</span><br><span style="color: hsl(120, 100%, 40%);">++            (event_src_type == PJSIP_EVENT_TIMER &&</span><br><span style="color: hsl(120, 100%, 40%);">++             (pj_timer_entry *)event_src == &tsx->timeout_timer))</span><br><span style="color: hsl(120, 100%, 40%);">+         {</span><br><span style="color: hsl(120, 100%, 40%);">+             pj_grp_lock_release(tsx->grp_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+         (*tsx->tsx_user->on_tsx_state)(tsx, &e);</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+-        if (event_src_type == PJSIP_EVENT_TIMER &&</span><br><span style="color: hsl(120, 100%, 40%);">+-            (pj_timer_entry *)event_src == &tsx->timeout_timer)</span><br><span style="color: hsl(120, 100%, 40%);">++        if ((flag & RELEASE_LOCK) != 0 ||</span><br><span style="color: hsl(120, 100%, 40%);">++            (event_src_type == PJSIP_EVENT_TIMER &&</span><br><span style="color: hsl(120, 100%, 40%);">++             (pj_timer_entry *)event_src == &tsx->timeout_timer))</span><br><span style="color: hsl(120, 100%, 40%);">+         {</span><br><span style="color: hsl(120, 100%, 40%);">+             pj_grp_lock_acquire(tsx->grp_lock);</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -2044,14 +2047,12 @@ static void send_msg_callback( pjsip_send_state *send_state,</span><br><span style="color: hsl(120, 100%, 40%);">+             if (tsx->state != PJSIP_TSX_STATE_TERMINATED &&</span><br><span style="color: hsl(120, 100%, 40%);">+                 tsx->state != PJSIP_TSX_STATE_DESTROYED)</span><br><span style="color: hsl(120, 100%, 40%);">+             {</span><br><span style="color: hsl(120, 100%, 40%);">+-                pj_time_val delay = {0, 0};</span><br><span style="color: hsl(120, 100%, 40%);">+-</span><br><span style="color: hsl(120, 100%, 40%);">+-                /* Post the event for later processing, to avoid deadlock. */</span><br><span style="color: hsl(120, 100%, 40%);">+-                lock_timer(tsx);</span><br><span style="color: hsl(120, 100%, 40%);">+-                tsx_cancel_timer(tsx, &tsx->timeout_timer);</span><br><span style="color: hsl(120, 100%, 40%);">+-                tsx_schedule_timer(tsx, &tsx->timeout_timer, &delay,</span><br><span style="color: hsl(120, 100%, 40%);">+-                                   TRANSPORT_ERR_TIMER);</span><br><span style="color: hsl(120, 100%, 40%);">+-                unlock_timer(tsx);</span><br><span style="color: hsl(120, 100%, 40%);">++                /* Set tsx state to TERMINATED, but release the lock</span><br><span style="color: hsl(120, 100%, 40%);">++                 * when invoking the callback, to avoid deadlock.</span><br><span style="color: hsl(120, 100%, 40%);">++                 */</span><br><span style="color: hsl(120, 100%, 40%);">++                tsx_set_state( tsx, PJSIP_TSX_STATE_TERMINATED,</span><br><span style="color: hsl(120, 100%, 40%);">++                               PJSIP_EVENT_TRANSPORT_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">++                               send_state->tdata, RELEASE_LOCK);</span><br><span style="color: hsl(120, 100%, 40%);">+             } </span><br><span style="color: hsl(120, 100%, 40%);">+             /* Don't forget to destroy if we have pending destroy flag</span><br><span style="color: hsl(120, 100%, 40%);">+              * (https://github.com/pjsip/pjproject/issues/906)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/20038">change 20038</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/20038"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Iac7972d8e0a4b10db88335dd170d818571fdc814 </div>
<div style="display:none"> Gerrit-Change-Number: 20038 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Stanislav Abramenkov <stas.abramenkov@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>