]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Core/PBX: Deadlock between dialplan execution and application unregistration.
authorFrederic LE FOLL <frederic.lefoll@c-s.fr>
Thu, 8 Jun 2017 17:28:12 +0000 (19:28 +0200)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 16 Jun 2017 18:26:11 +0000 (13:26 -0500)
Not easy to reproduce, but we have noticed deadlocks when unloading a module
while dialplan is handling a request.

The deadlock is between :
1) Dialplan execution: pbx_extension_helper() first taking conlock,
then pbx_findapp() [when called] asking for lock on apps list.
2) Application unregistration: ast_unregister_application() first taking lock
on apps list, then unreference_cached_app() [when called] asking for conlock.

As a protection, I suggest to modify ast_unregister_application(), so that it
anticipates the need of conlock, before taking the lock on apps list.
The side effect is a longer unavailability of conlock when unregistering an
application.

ASTERISK-27041

Change-Id: I0db0f1eb320da6a5758cce3a47d765be1face8e2

main/pbx_app.c

index 7dabda30d95fabc0697d63681f7fd9616eac1315..e39ad3f8ef282eac6a47eb88aa4ccd47b1cda71c 100644 (file)
@@ -396,6 +396,11 @@ int ast_unregister_application(const char *app)
        struct ast_app *cur;
        int cmp;
 
+       /* Anticipate need for conlock in unreference_cached_app(), in order to avoid
+        * possible deadlock with pbx_extension_helper()/pbx_findapp()
+        */
+       ast_rdlock_contexts();
+
        AST_RWLIST_WRLOCK(&apps);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
                cmp = strcasecmp(app, cur->name);
@@ -418,6 +423,8 @@ int ast_unregister_application(const char *app)
        AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&apps);
 
+       ast_unlock_contexts();
+
        return cur ? 0 : -1;
 }