<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13718">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis/app: don't lock an app before a call to send<br><br>Calling 'app_send' eventually calls the app's message handler. It's possible<br>for a handler to obtain a lock on another object, and then need/want to lock<br>the app object. If the caller of 'app_send' locks the app object prior to<br>calling then there's a potential for a deadlock, if another thread calls<br>'app_send' without locking.<br><br>This patch makes it so 'app_send' is not called with the app object locked in<br>the section of code doing such.<br><br>ASTERISK-28423 #close<br><br>Change-Id: I6767c6d0933c7db1b984018966eefca4c0638a27<br>(cherry picked from commit 737bd8365e09b7f4229a16662fc40583fb0a32bf)<br>---<br>M res/stasis/app.c<br>1 file changed, 15 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/stasis/app.c b/res/stasis/app.c</span><br><span>index aba2661..ee2fd0b 100644</span><br><span>--- a/res/stasis/app.c</span><br><span>+++ b/res/stasis/app.c</span><br><span>@@ -1126,8 +1126,23 @@</span><br><span>                       "timestamp", ast_json_timeval(ast_tvnow(), NULL),</span><br><span>                  "application", app->name);</span><br><span>              if (msg) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    /*</span><br><span style="color: hsl(120, 100%, 40%);">+                     * The app must be unlocked before calling 'send' since a handler may</span><br><span style="color: hsl(120, 100%, 40%);">+                  * subsequently attempt to grab the app lock after first obtaining a</span><br><span style="color: hsl(120, 100%, 40%);">+                   * lock for another object, thus causing a deadlock.</span><br><span style="color: hsl(120, 100%, 40%);">+                   */</span><br><span style="color: hsl(120, 100%, 40%);">+                   ao2_unlock(app);</span><br><span>                     app_send(app, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                   ao2_lock(app);</span><br><span>                       ast_json_unref(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                  if (!app->handler) {</span><br><span style="color: hsl(120, 100%, 40%);">+                               /*</span><br><span style="color: hsl(120, 100%, 40%);">+                             * If the handler disappeared then the app was deactivated. In that</span><br><span style="color: hsl(120, 100%, 40%);">+                            * case don't replace. Re-activation will reset the handler later.</span><br><span style="color: hsl(120, 100%, 40%);">+                                 */</span><br><span style="color: hsl(120, 100%, 40%);">+                           ao2_unlock(app);</span><br><span style="color: hsl(120, 100%, 40%);">+                              return;</span><br><span style="color: hsl(120, 100%, 40%);">+                       }</span><br><span>            }</span><br><span>    } else {</span><br><span>             ast_verb(1, "Activating Stasis app '%s'\n", app->name);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13718">change 13718</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/+/13718"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17.2 </div>
<div style="display:none"> Gerrit-Change-Id: I6767c6d0933c7db1b984018966eefca4c0638a27 </div>
<div style="display:none"> Gerrit-Change-Number: 13718 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-CC: Friendly Automation </div>
<div style="display:none"> Gerrit-MessageType: merged </div>