<p>Giuseppe Sucameli has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10701">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Fix deadlock handling subscribe req during res_parking reload<br><br>Split destroy_hint method to separate hint removal and extension hint<br>state changed callback, the latter now called via stasis.<br>This avoids deadlock between res_parking reload that is removing the<br>parking lot and the related hint and subscribe requests coming for the<br>same parking lot.<br><br>ASTERISK-28173<br><br>Change-Id: I5b03c3455b3b12b6f83cea4cc34f4b4b20444f7e<br>---<br>M main/pbx.c<br>1 file changed, 30 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/10701/1</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 173b62e..08805cf 100644</span><br><span>--- a/main/pbx.c</span><br><span>+++ b/main/pbx.c</span><br><span>@@ -3311,8 +3311,31 @@</span><br><span> </span><br><span>       ao2_lock(hint);</span><br><span>      if (!hint->exten) {</span><br><span style="color: hsl(0, 100%, 40%);">-          /* The extension has already been destroyed */</span><br><span style="color: hsl(120, 100%, 40%);">+                /* The extension has already been destroyed,</span><br><span style="color: hsl(120, 100%, 40%);">+           * notify extension deactivation</span><br><span style="color: hsl(120, 100%, 40%);">+               */</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!hint->callbacks) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    ao2_unlock(hint);</span><br><span style="color: hsl(120, 100%, 40%);">+                     return;</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%);">+           ast_copy_string(context_name, hint->context_name, sizeof(context_name));</span><br><span style="color: hsl(120, 100%, 40%);">+           ast_copy_string(exten_name, hint->exten_name, sizeof(exten_name));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               hint->laststate = AST_EXTENSION_DEACTIVATED;</span><br><span>              ao2_unlock(hint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           cb_iter = ao2_iterator_init(hint->callbacks, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+           for (; (state_cb = ao2_iterator_next(&cb_iter)); ao2_ref(state_cb, -1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 execute_state_callback(state_cb->change_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+                                context_name,</span><br><span style="color: hsl(120, 100%, 40%);">+                         exten_name,</span><br><span style="color: hsl(120, 100%, 40%);">+                           state_cb->data,</span><br><span style="color: hsl(120, 100%, 40%);">+                            AST_HINT_UPDATE_DEVICE,</span><br><span style="color: hsl(120, 100%, 40%);">+                               hint,</span><br><span style="color: hsl(120, 100%, 40%);">+                         NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_iterator_destroy(&cb_iter);</span><br><span>          return;</span><br><span>      }</span><br><span> </span><br><span>@@ -3808,31 +3831,7 @@</span><br><span>       int i;</span><br><span> </span><br><span>   if (hint->callbacks) {</span><br><span style="color: hsl(0, 100%, 40%);">-               struct ast_state_cb *state_cb;</span><br><span style="color: hsl(0, 100%, 40%);">-          const char *context_name;</span><br><span style="color: hsl(0, 100%, 40%);">-               const char *exten_name;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-         if (hint->exten) {</span><br><span style="color: hsl(0, 100%, 40%);">-                   context_name = ast_get_context_name(ast_get_extension_context(hint->exten));</span><br><span style="color: hsl(0, 100%, 40%);">-                 exten_name = ast_get_extension_name(hint->exten);</span><br><span style="color: hsl(0, 100%, 40%);">-                    hint->exten = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-          } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                        /* The extension has already been destroyed */</span><br><span style="color: hsl(0, 100%, 40%);">-                  context_name = hint->context_name;</span><br><span style="color: hsl(0, 100%, 40%);">-                   exten_name = hint->exten_name;</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-               hint->laststate = AST_EXTENSION_DEACTIVATED;</span><br><span style="color: hsl(0, 100%, 40%);">-         while ((state_cb = ao2_callback(hint->callbacks, OBJ_UNLINK, NULL, NULL))) {</span><br><span style="color: hsl(0, 100%, 40%);">-                 /* Notify with -1 and remove all callbacks */</span><br><span style="color: hsl(0, 100%, 40%);">-                   execute_state_callback(state_cb->change_cb,</span><br><span style="color: hsl(0, 100%, 40%);">-                          context_name,</span><br><span style="color: hsl(0, 100%, 40%);">-                           exten_name,</span><br><span style="color: hsl(0, 100%, 40%);">-                             state_cb->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                              AST_HINT_UPDATE_DEVICE,</span><br><span style="color: hsl(0, 100%, 40%);">-                         hint,</span><br><span style="color: hsl(0, 100%, 40%);">-                           NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-                  ao2_ref(state_cb, -1);</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_callback(hint->callbacks, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);</span><br><span>                ao2_ref(hint->callbacks, -1);</span><br><span>     }</span><br><span> </span><br><span>@@ -3845,6 +3844,8 @@</span><br><span>        ast_free(hint->last_presence_message);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int publish_hint_change(struct ast_hint *hint, struct ast_exten *ne);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Remove hint from extension */</span><br><span> static int ast_remove_hint(struct ast_exten *e)</span><br><span> {</span><br><span>@@ -3875,6 +3876,8 @@</span><br><span>       hint->exten = NULL;</span><br><span>       ao2_unlock(hint);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ publish_hint_change(hint, e);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      ao2_ref(hint, -1);</span><br><span> </span><br><span>       return 0;</span><br><span>@@ -3981,9 +3984,7 @@</span><br><span>            return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* The message is going to be published to two topics so the hint needs two refs */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!(message = stasis_message_create(hint_change_message_type(), ao2_bump(hint)))) {</span><br><span style="color: hsl(0, 100%, 40%);">-           ao2_ref(hint, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!(message = stasis_message_create(hint_change_message_type(), hint))) {</span><br><span>          return -1;</span><br><span>   }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10701">change 10701</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/10701"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: certified/13.18 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I5b03c3455b3b12b6f83cea4cc34f4b4b20444f7e </div>
<div style="display:none"> Gerrit-Change-Number: 10701 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Giuseppe Sucameli <sucameli@netresults.it> </div>