<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13173">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">parking: Use channel snapshot instead of channel.<br><br>There exists a scenario where a thread can hold a lock on the<br>channels container while trying to lock a bridge. At the same<br>time another thread can hold the lock for said bridge while<br>attempting to retrieve a channel. This causes a deadlock.<br><br>This change fixes this scenario by retrieving a channel snapshot<br>instead of a channel, as information present in the snapshot<br>is all that is needed.<br><br>ASTERISK-28616<br><br>Change-Id: I68ceb1d62c7378addcd286e21be08a660a7cecf2<br>---<br>M res/parking/parking_bridge.c<br>1 file changed, 8 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/73/13173/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/parking/parking_bridge.c b/res/parking/parking_bridge.c</span><br><span>index e61486e..5736ace 100644</span><br><span>--- a/res/parking/parking_bridge.c</span><br><span>+++ b/res/parking/parking_bridge.c</span><br><span>@@ -72,9 +72,9 @@</span><br><span> }</span><br><span> </span><br><span> /* Only call this on a parked user that hasn't had its parker_dial_string set already */</span><br><span style="color: hsl(0, 100%, 40%);">-static int parked_user_set_parker_dial_string(struct parked_user *pu, struct ast_channel *parker)</span><br><span style="color: hsl(120, 100%, 40%);">+static int parked_user_set_parker_dial_string(struct parked_user *pu, struct ast_channel_snapshot *parker)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char *dial_string = ast_strdupa(ast_channel_name(parker));</span><br><span style="color: hsl(120, 100%, 40%);">+ char *dial_string = ast_strdupa(parker->name);</span><br><span> </span><br><span> ast_channel_name_to_dial_string(dial_string);</span><br><span> pu->parker_dial_string = ast_strdup(dial_string);</span><br><span>@@ -93,7 +93,7 @@</span><br><span> *</span><br><span> * \param lot The parking lot we are assigning the user to</span><br><span> * \param parkee The channel being parked</span><br><span style="color: hsl(0, 100%, 40%);">- * \param parker The channel performing the park operation (may be the same channel)</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param parker The snapshot of the channel performing the park operation (may be the same channel)</span><br><span> * \param parker_dial_string Takes priority over parker for setting the parker dial string if included</span><br><span> * \param use_random_space if true, prioritize using a random parking space instead</span><br><span> * of ${PARKINGEXTEN} and/or automatic assignment from the parking lot</span><br><span>@@ -106,7 +106,7 @@</span><br><span> *</span><br><span> * \note ao2_cleanup this reference when you are done using it or you'll cause leaks.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static struct parked_user *generate_parked_user(struct parking_lot *lot, struct ast_channel *chan, struct ast_channel *parker, const char *parker_dial_string, int use_random_space, int time_limit)</span><br><span style="color: hsl(120, 100%, 40%);">+static struct parked_user *generate_parked_user(struct parking_lot *lot, struct ast_channel *chan, struct ast_channel_snapshot *parker, const char *parker_dial_string, int use_random_space, int time_limit)</span><br><span> {</span><br><span> struct parked_user *new_parked_user;</span><br><span> int preferred_space = -1; /* Initialize to use parking lot defaults */</span><br><span>@@ -207,7 +207,7 @@</span><br><span> {</span><br><span> struct parked_user *pu;</span><br><span> const char *blind_transfer;</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_channel *, parker, NULL, ao2_cleanup); /* XXX replace with ast_channel_cleanup when available */</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_channel_snapshot *, parker, NULL, ao2_cleanup);</span><br><span> RAII_VAR(struct park_common_datastore *, park_datastore, NULL, park_common_datastore_free);</span><br><span> </span><br><span> ast_bridge_base_v_table.push(&self->base, bridge_channel, swap);</span><br><span>@@ -263,7 +263,7 @@</span><br><span> /* There was either a failure to apply the datastore when performing park common setup or else we had alloc failures while cloning. Abort. */</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- parker = ast_channel_get_by_name(park_datastore->parker_uuid);</span><br><span style="color: hsl(120, 100%, 40%);">+ parker = ast_channel_snapshot_get_latest(park_datastore->parker_uuid);</span><br><span> </span><br><span> /* If the parker and the parkee are the same channel pointer, then the channel entered using</span><br><span> * the park application. It's possible that the channel that transferred it is still alive (particularly</span><br><span>@@ -272,9 +272,9 @@</span><br><span> blind_transfer = pbx_builtin_getvar_helper(bridge_channel->chan, "BLINDTRANSFER");</span><br><span> blind_transfer = ast_strdupa(S_OR(blind_transfer, ""));</span><br><span> ast_channel_unlock(bridge_channel->chan);</span><br><span style="color: hsl(0, 100%, 40%);">- if ((!parker || parker == bridge_channel->chan)</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((!parker || !strcmp(parker->name, ast_channel_name(bridge_channel->chan)))</span><br><span> && !ast_strlen_zero(blind_transfer)) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_channel *real_parker = ast_channel_get_by_name(blind_transfer);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel_snapshot *real_parker = ast_channel_snapshot_get_latest_by_name(blind_transfer);</span><br><span> </span><br><span> if (real_parker) {</span><br><span> ao2_cleanup(parker);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13173">change 13173</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/c/asterisk/+/13173"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I68ceb1d62c7378addcd286e21be08a660a7cecf2 </div>
<div style="display:none"> Gerrit-Change-Number: 13173 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>