[Asterisk-code-review] Fix deadlock handling subscribe req during res parking reload (asterisk[certified/13.18])
Giuseppe Sucameli
asteriskteam at digium.com
Mon Nov 19 18:48:11 CST 2018
Giuseppe Sucameli has uploaded this change for review. ( https://gerrit.asterisk.org/10701
Change subject: Fix deadlock handling subscribe req during res_parking reload
......................................................................
Fix deadlock handling subscribe req during res_parking reload
Split destroy_hint method to separate hint removal and extension hint
state changed callback, the latter now called via stasis.
This avoids deadlock between res_parking reload that is removing the
parking lot and the related hint and subscribe requests coming for the
same parking lot.
ASTERISK-28173
Change-Id: I5b03c3455b3b12b6f83cea4cc34f4b4b20444f7e
---
M main/pbx.c
1 file changed, 30 insertions(+), 29 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/10701/1
diff --git a/main/pbx.c b/main/pbx.c
index 173b62e..08805cf 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3311,8 +3311,31 @@
ao2_lock(hint);
if (!hint->exten) {
- /* The extension has already been destroyed */
+ /* The extension has already been destroyed,
+ * notify extension deactivation
+ */
+ if (!hint->callbacks) {
+ ao2_unlock(hint);
+ return;
+ }
+
+ ast_copy_string(context_name, hint->context_name, sizeof(context_name));
+ ast_copy_string(exten_name, hint->exten_name, sizeof(exten_name));
+
+ hint->laststate = AST_EXTENSION_DEACTIVATED;
ao2_unlock(hint);
+
+ cb_iter = ao2_iterator_init(hint->callbacks, 0);
+ for (; (state_cb = ao2_iterator_next(&cb_iter)); ao2_ref(state_cb, -1)) {
+ execute_state_callback(state_cb->change_cb,
+ context_name,
+ exten_name,
+ state_cb->data,
+ AST_HINT_UPDATE_DEVICE,
+ hint,
+ NULL);
+ }
+ ao2_iterator_destroy(&cb_iter);
return;
}
@@ -3808,31 +3831,7 @@
int i;
if (hint->callbacks) {
- struct ast_state_cb *state_cb;
- const char *context_name;
- const char *exten_name;
-
- if (hint->exten) {
- context_name = ast_get_context_name(ast_get_extension_context(hint->exten));
- exten_name = ast_get_extension_name(hint->exten);
- hint->exten = NULL;
- } else {
- /* The extension has already been destroyed */
- context_name = hint->context_name;
- exten_name = hint->exten_name;
- }
- hint->laststate = AST_EXTENSION_DEACTIVATED;
- while ((state_cb = ao2_callback(hint->callbacks, OBJ_UNLINK, NULL, NULL))) {
- /* Notify with -1 and remove all callbacks */
- execute_state_callback(state_cb->change_cb,
- context_name,
- exten_name,
- state_cb->data,
- AST_HINT_UPDATE_DEVICE,
- hint,
- NULL);
- ao2_ref(state_cb, -1);
- }
+ ao2_callback(hint->callbacks, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, NULL, NULL);
ao2_ref(hint->callbacks, -1);
}
@@ -3845,6 +3844,8 @@
ast_free(hint->last_presence_message);
}
+static int publish_hint_change(struct ast_hint *hint, struct ast_exten *ne);
+
/*! \brief Remove hint from extension */
static int ast_remove_hint(struct ast_exten *e)
{
@@ -3875,6 +3876,8 @@
hint->exten = NULL;
ao2_unlock(hint);
+ publish_hint_change(hint, e);
+
ao2_ref(hint, -1);
return 0;
@@ -3981,9 +3984,7 @@
return -1;
}
- /* The message is going to be published to two topics so the hint needs two refs */
- if (!(message = stasis_message_create(hint_change_message_type(), ao2_bump(hint)))) {
- ao2_ref(hint, -1);
+ if (!(message = stasis_message_create(hint_change_message_type(), hint))) {
return -1;
}
--
To view, visit https://gerrit.asterisk.org/10701
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.18
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b03c3455b3b12b6f83cea4cc34f4b4b20444f7e
Gerrit-Change-Number: 10701
Gerrit-PatchSet: 1
Gerrit-Owner: Giuseppe Sucameli <sucameli at netresults.it>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181119/b9194ffa/attachment-0001.html>
More information about the asterisk-code-review
mailing list