<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5973">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Michael Walton: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_rtp_asterisk.c: Fix TURN deadlock by using ICE session group lock.<br><br>When a message is received on the TURN socket, the code processing the<br>message needs to call into the ICE/STUN session for further processing.<br>This code path locks the TURN group lock then the ICE/STUN group lock. In<br>another thread an ICE/STUN timer can fire off to send a keep alive message<br>over the TURN socket. In this code path, the ICE/STUN group lock is<br>obtained then the TURN group lock is obtained to send the packet. A<br>classic deadlock case if the group locks are not the same.<br><br>* Made TURN get created using the ICE/STUN session's group lock.<br><br>NOTE: I was originally concerned that the ICE/STUN session can get<br>recreated by ice_reset_session() for an event like RTCP multiplexing<br>causing a change during SDP negotiation. In this case the TURN group lock<br>would become different. However, TURN is also recreated as part of the<br>ICE/STUN recreation in ice_create() when all known ICE candidates are<br>added to the new ICE session. While the ICE/STUN and TURN sessions are<br>being recreated there is a period where the group locks could be<br>different.<br><br>ASTERISK-27023 #close<br>Patches:<br> res_rtp_asterisk-turn-deadlock-fix.patch (license #6502)<br> patch uploaded by Michael Walton (modified)<br><br>Change-Id: Ic870edb99ce4988a8c8eb6e678ca7f19da1432b9<br>---<br>M res/res_rtp_asterisk.c<br>1 file changed, 12 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c<br>index 01dfe76..e60d4af 100644<br>--- a/res/res_rtp_asterisk.c<br>+++ b/res/res_rtp_asterisk.c<br>@@ -1293,6 +1293,8 @@<br> pj_turn_session_info info;<br> struct ast_sockaddr local, loop;<br> pj_status_t status;<br>+ pj_turn_sock_cfg turn_sock_cfg;<br>+ struct ice_wrap *ice;<br> <br> ast_rtp_instance_get_local_address(instance, &local);<br> if (ast_sockaddr_is_ipv4(&local)) {<br>@@ -1355,11 +1357,20 @@<br> <br> pj_stun_config_init(&stun_config, &cachingpool.factory, 0, rtp->ioqueue->ioqueue, rtp->ioqueue->timerheap);<br> <br>+ /* Use ICE session group lock for TURN session to avoid deadlock */<br>+ pj_turn_sock_cfg_default(&turn_sock_cfg);<br>+ ice = rtp->ice;<br>+ if (ice) {<br>+ turn_sock_cfg.grp_lock = ice->real_ice->grp_lock;<br>+ ao2_ref(ice, +1);<br>+ }<br>+<br> /* Release the instance lock to avoid deadlock with PJPROJECT group lock */<br> ao2_unlock(instance);<br> status = pj_turn_sock_create(&stun_config,<br> ast_sockaddr_is_ipv4(&addr) ? pj_AF_INET() : pj_AF_INET6(), conn_type,<br>- turn_cb, NULL, instance, turn_sock);<br>+ turn_cb, &turn_sock_cfg, instance, turn_sock);<br>+ ao2_cleanup(ice);<br> if (status != PJ_SUCCESS) {<br> ast_log(LOG_WARNING, "Could not create a TURN client socket\n");<br> ao2_lock(instance);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5973">change 5973</a>. To unsubscribe, 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/5973"/><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: Ic870edb99ce4988a8c8eb6e678ca7f19da1432b9 </div>
<div style="display:none"> Gerrit-Change-Number: 5973 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael Walton <mike@farsouthnet.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>