<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19374">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">sla: Prevent deadlock and crash due to autoservicing.<br><br>SLAStation currently autoservices the station channel before<br>creating a thread to actually dial the trunk. This leads<br>to duplicate servicing of the channel which causes assertions,<br>deadlocks, crashes, and moreover not the correct behavior.<br><br>Removing the autoservice prevents the crash, but if the station<br>hangs up before the trunk answers, the call hangs since the hangup<br>was never serviced on the channel.<br><br>This is fixed by not autoservicing the channel, but instead<br>servicing it in the thread dialing the trunk, since it is doing<br>so synchronously to begin with. Instead of sleeping for 100ms<br>in a loop, we simply use the channel for timing, and abort<br>if it disappears.<br><br>The same issue also occurs with SLATrunk when a call is answered,<br>because ast_answer invokes ast_waitfor_nandfds. Thus, we use<br>ast_raw_answer instead which does not cause any conflict and allows<br>the call to be answered normally without thread blocking issues.<br><br>ASTERISK-29998 #close<br><br>Change-Id: Icc237d50354b5910000d2305901e86d2c87bb9d8<br>---<br>M apps/app_meetme.c<br>1 file changed, 48 insertions(+), 7 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_meetme.c b/apps/app_meetme.c</span><br><span>index 0f717b3..8b5bd40 100644</span><br><span>--- a/apps/app_meetme.c</span><br><span>+++ b/apps/app_meetme.c</span><br><span>@@ -6149,7 +6149,7 @@</span><br><span> </span><br><span> static void answer_trunk_chan(struct ast_channel *chan)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_answer(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_raw_answer(chan);</span><br><span>        ast_indicate(chan, -1);</span><br><span> }</span><br><span> </span><br><span>@@ -6994,8 +6994,18 @@</span><br><span>            return NULL;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   for (;;) {</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Wait for dial to end, while servicing the channel */</span><br><span style="color: hsl(120, 100%, 40%);">+       while (ast_waitfor(trunk_ref->chan, 100)) {</span><br><span>               unsigned int done = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+                struct ast_frame *fr = ast_read(trunk_ref->chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                if (!fr) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    ast_debug(1, "Channel %s did not return a frame, must have hung up\n", ast_channel_name(trunk_ref->chan));</span><br><span style="color: hsl(120, 100%, 40%);">+                       done = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+                     break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_frfree(fr); /* Ignore while dialing */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                 switch ((dial_res = ast_dial_state(dial))) {</span><br><span>                 case AST_DIAL_RESULT_ANSWERED:</span><br><span>                       trunk_ref->trunk->chan = ast_dial_answered(dial);</span><br><span>@@ -7032,8 +7042,6 @@</span><br><span>                      last_state = current_state;</span><br><span>          }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           /* avoid tight loop... sleep for 1/10th second */</span><br><span style="color: hsl(0, 100%, 40%);">-               ast_safe_sleep(trunk_ref->chan, 100);</span><br><span>     }</span><br><span> </span><br><span>        if (!trunk_ref->trunk->chan) {</span><br><span>@@ -7192,8 +7200,10 @@</span><br><span>                sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);</span><br><span>               /* Create a thread to dial the trunk and dump it into the conference.</span><br><span>                 * However, we want to wait until the trunk has been dialed and the</span><br><span style="color: hsl(0, 100%, 40%);">-              * conference is created before continuing on here. */</span><br><span style="color: hsl(0, 100%, 40%);">-          ast_autoservice_start(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+           * conference is created before continuing on here.</span><br><span style="color: hsl(120, 100%, 40%);">+            * Don't autoservice the channel or we'll have multiple threads</span><br><span style="color: hsl(120, 100%, 40%);">+                * handling it. dial_trunk services the channel.</span><br><span style="color: hsl(120, 100%, 40%);">+               */</span><br><span>          ast_mutex_init(&cond_lock);</span><br><span>              ast_cond_init(&cond, NULL);</span><br><span>              ast_mutex_lock(&cond_lock);</span><br><span>@@ -7202,7 +7212,7 @@</span><br><span>              ast_mutex_unlock(&cond_lock);</span><br><span>            ast_mutex_destroy(&cond_lock);</span><br><span>           ast_cond_destroy(&cond);</span><br><span style="color: hsl(0, 100%, 40%);">-            ast_autoservice_stop(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                if (!trunk_ref->trunk->chan) {</span><br><span>                         ast_debug(1, "Trunk didn't get created. chan: %lx\n", (unsigned long) trunk_ref->trunk->chan);</span><br><span>                   pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19374">change 19374</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/+/19374"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Icc237d50354b5910000d2305901e86d2c87bb9d8 </div>
<div style="display:none"> Gerrit-Change-Number: 19374 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>