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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pbx: Fix hints deadlock between reload and ExtensionState.<br><br>When the ExtensionState AMI action is executed on a pattern matched<br>hint it can end up adding a new hint if one does not already exist.<br>This results in a locking order of contexts -> hints -> contexts.<br><br>If at the same time a reload is occurring and adding its own hint<br>it will have a locking order of hints -> contexts.<br><br>This results in a deadlock as one thread wants a lock on contexts<br>that the other has, and the other thread wants a lock on hints<br>that the other has.<br><br>This change enforces a hints -> contexts locking order by explicitly<br>locking hints in the places where a hint is added when queried for.<br>This matches the order seen through normal adding of hints.<br><br>ASTERISK-29046<br><br>Change-Id: I49f027f4aab5d2d50855ae937bcf5e2fd8bfc504<br>---<br>M main/pbx.c<br>1 file changed, 10 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/pbx.c b/main/pbx.c</span><br><span>index bbc6df9..b520f5f 100644</span><br><span>--- a/main/pbx.c</span><br><span>+++ b/main/pbx.c</span><br><span>@@ -3148,10 +3148,15 @@</span><br><span>     }</span><br><span> </span><br><span>        if (e->exten[0] == '_') {</span><br><span style="color: hsl(0, 100%, 40%);">-            /* Create this hint on-the-fly */</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Create this hint on-the-fly, we explicitly lock hints here to ensure the</span><br><span style="color: hsl(120, 100%, 40%);">+            * same locking order as if this were done through configuration file - that is</span><br><span style="color: hsl(120, 100%, 40%);">+                * hints is locked first and then (if needed) contexts is locked</span><br><span style="color: hsl(120, 100%, 40%);">+               */</span><br><span style="color: hsl(120, 100%, 40%);">+           ao2_lock(hints);</span><br><span>             ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,</span><br><span>                      e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,</span><br><span>                     e->registrar);</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_unlock(hints);</span><br><span>           if (!(e = ast_hint_extension(c, context, exten))) {</span><br><span>                  /* Improbable, but not impossible */</span><br><span>                         return -1;</span><br><span>@@ -3228,9 +3233,11 @@</span><br><span> </span><br><span>      if (e->exten[0] == '_') {</span><br><span>                 /* Create this hint on-the-fly */</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_lock(hints);</span><br><span>             ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,</span><br><span>                      e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,</span><br><span>                     e->registrar);</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_unlock(hints);</span><br><span>           if (!(e = ast_hint_extension(c, context, exten))) {</span><br><span>                  /* Improbable, but not impossible */</span><br><span>                         return -1;</span><br><span>@@ -3766,9 +3773,11 @@</span><br><span>   * individual extension, because the pattern will no longer match first.</span><br><span>      */</span><br><span>  if (e->exten[0] == '_') {</span><br><span style="color: hsl(120, 100%, 40%);">+          ao2_lock(hints);</span><br><span>             ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,</span><br><span>                      e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,</span><br><span>                     e->registrar);</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_unlock(hints);</span><br><span>           e = ast_hint_extension(NULL, context, exten);</span><br><span>                if (!e || e->exten[0] == '_') {</span><br><span>                   return -1;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14847">change 14847</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/+/14847"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16.13 </div>
<div style="display:none"> Gerrit-Change-Id: I49f027f4aab5d2d50855ae937bcf5e2fd8bfc504 </div>
<div style="display:none"> Gerrit-Change-Number: 14847 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </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-MessageType: merged </div>