<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10959">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Friendly Automation: Verified
George Joseph: Looks good to me, approved; Approved for Submit
</div><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, 55 insertions(+), 30 deletions(-)<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 9e19f35..ee5ed7e 100644</span><br><span>--- a/main/pbx.c</span><br><span>+++ b/main/pbx.c</span><br><span>@@ -346,6 +346,7 @@</span><br><span> };</span><br><span> </span><br><span> STASIS_MESSAGE_TYPE_DEFN_LOCAL(hint_change_message_type);</span><br><span style="color: hsl(120, 100%, 40%);">+STASIS_MESSAGE_TYPE_DEFN_LOCAL(hint_remove_message_type);</span><br><span> </span><br><span> #define HINTDEVICE_DATA_LENGTH 16</span><br><span> AST_THREADSTORAGE(hintdevice_data);</span><br><span>@@ -3570,6 +3571,30 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (hint_remove_message_type() == stasis_message_type(msg)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* The extension has already been destroyed */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_state_cb *state_cb;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator cb_iter;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_hint *hint = stasis_message_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(hint);</span><br><span style="color: hsl(120, 100%, 40%);">+ hint->laststate = AST_EXTENSION_DEACTIVATED;</span><br><span style="color: hsl(120, 100%, 40%);">+ 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%);">+ hint->context_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ hint->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 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> if (ast_device_state_message_type() != stasis_message_type(msg)) {</span><br><span> return;</span><br><span> }</span><br><span>@@ -3855,34 +3880,7 @@</span><br><span> struct ast_hint *hint = obj;</span><br><span> int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- 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(0, 100%, 40%);">- ao2_ref(hint->callbacks, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(hint->callbacks);</span><br><span> </span><br><span> for (i = 0; i < AST_VECTOR_SIZE(&hint->devices); i++) {</span><br><span> char *device = AST_VECTOR_GET(&hint->devices, i);</span><br><span>@@ -3893,6 +3891,27 @@</span><br><span> ast_free(hint->last_presence_message);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Publish a hint removed event */</span><br><span style="color: hsl(120, 100%, 40%);">+static int publish_hint_remove(struct ast_hint *hint)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_message *message;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!hint_remove_message_type()) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+ if (!(message = stasis_message_create(hint_remove_message_type(), hint))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(hint, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</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%);">+ stasis_publish(ast_device_state_topic_all(), message);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(message, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</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>@@ -3923,6 +3942,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_remove(hint);</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>@@ -4029,8 +4050,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(120, 100%, 40%);">+ if (!(message = stasis_message_create(hint_change_message_type(), hint))) {</span><br><span> ao2_ref(hint, -1);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -8418,6 +8438,7 @@</span><br><span> }</span><br><span> stasis_subscription_accept_message_type(device_state_sub, ast_device_state_message_type());</span><br><span> stasis_subscription_accept_message_type(device_state_sub, hint_change_message_type());</span><br><span style="color: hsl(120, 100%, 40%);">+ stasis_subscription_accept_message_type(device_state_sub, hint_remove_message_type());</span><br><span> stasis_subscription_set_filter(device_state_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);</span><br><span> </span><br><span> if (!(presence_state_sub = stasis_subscribe(ast_presence_state_topic_all(), presence_state_cb, NULL))) {</span><br><span>@@ -8841,6 +8862,7 @@</span><br><span> static void pbx_shutdown(void)</span><br><span> {</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(hint_change_message_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ STASIS_MESSAGE_TYPE_CLEANUP(hint_remove_message_type);</span><br><span> </span><br><span> if (hints) {</span><br><span> ao2_container_unregister("hints");</span><br><span>@@ -8938,6 +8960,9 @@</span><br><span> if (STASIS_MESSAGE_TYPE_INIT(hint_change_message_type) != 0) {</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (STASIS_MESSAGE_TYPE_INIT(hint_remove_message_type) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return (hints && hintdevices && autohints && statecbs) ? 0 : -1;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10959">change 10959</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/10959"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I5b03c3455b3b12b6f83cea4cc34f4b4b20444f7e </div>
<div style="display:none"> Gerrit-Change-Number: 10959 </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: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Giuseppe Sucameli <sucameli@netresults.it> </div>