[Asterisk-code-review] bridge: Unlock channel during Local peer check. (asterisk[16])

Joshua Colp asteriskteam at digium.com
Mon Dec 27 07:29:31 CST 2021


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17741 )


Change subject: bridge: Unlock channel during Local peer check.
......................................................................

bridge: Unlock channel during Local peer check.

It's not safe to keep the channel locked while locking
the peer Local channel, as it can result in a deadlock.

This change unlocks it during this time but keeps the
bridge locked to ensure nothing changes about the bridge.

ASTERISK-29821

Change-Id: Ib68eb7037e5a479bcc2aceee77337cdde1fbdde6
---
M main/bridge_channel.c
1 file changed, 5 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/41/17741/1

diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index 1f401c8..1b0f1dd 100644
--- a/main/bridge_channel.c
+++ b/main/bridge_channel.c
@@ -2861,11 +2861,13 @@
 	ast_bridge_lock(bridge_channel->bridge);
 
 	ast_channel_lock(bridge_channel->chan);
-
 	peer = ast_local_get_peer(bridge_channel->chan);
+
 	if (peer) {
 		struct ast_bridge *peer_bridge;
 
+		ast_channel_unlock(bridge_channel->chan);
+
 		ast_channel_lock(peer);
 		peer_bridge = ast_channel_internal_bridge(peer);
 		ast_channel_unlock(peer);
@@ -2875,7 +2877,6 @@
 		 * to be reference counted or locked.
 		 */
 		if (peer_bridge == bridge_channel->bridge) {
-			ast_channel_unlock(bridge_channel->chan);
 			ast_bridge_unlock(bridge_channel->bridge);
 			ast_debug(1, "Bridge %s: %p(%s) denying Bridge join to prevent Local channel loop\n",
 				bridge_channel->bridge->uniqueid,
@@ -2883,6 +2884,8 @@
 				ast_channel_name(bridge_channel->chan));
 			return -1;
 		}
+
+		ast_channel_lock(bridge_channel->chan);
 	}
 
 	bridge_channel->read_format = ao2_bump(ast_channel_readformat(bridge_channel->chan));

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17741
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ib68eb7037e5a479bcc2aceee77337cdde1fbdde6
Gerrit-Change-Number: 17741
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211227/e9c6eeb0/attachment.html>


More information about the asterisk-code-review mailing list