From: Matthew Jordan Date: Tue, 12 Jun 2012 13:44:36 +0000 (+0000) Subject: Fix deadlock in SIP transfers that involve a REFER request X-Git-Tag: certified/1.8.11-cert5-rc1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a44580b50926113fec95845e9b348eab6e14405c;p=thirdparty%2Fasterisk.git Fix deadlock in SIP transfers that involve a REFER request In r367163, "send to voicemail" functionality was added to the SIP channel driver. This required updating the party redirecting information for the channel based on the headers provided in the REFER request. When the redirecting party information is updated on the channel, a call to ast_indicate_data occurs. Because handle_request_refer still had the sip_pvt locked, a deadlock could occur between the pbx_thread and the do_monitor thread servicing the REFER request. This patch preserves the proper locking order between the channel and the sip_pvt by ensuring that the sip_pvt is unlocked prior to updating the party redirecting information on the channel. (closes issue AST-903) Reported by: Matt Jordan patches: jira_ast_903_trunk.patch by rmudgett (license 5621) git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/1.8.11@368790 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 4821b85629..dba896cbd6 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -23987,16 +23987,18 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int ast_party_redirecting_init(&redirecting); memset(&update_redirecting, 0, sizeof(update_redirecting)); change_redirecting_information(p, req, &redirecting, &update_redirecting, FALSE); + + /* Do not hold the pvt lock during a call that causes an indicate or an async_goto. + * Those functions lock channels which will invalidate locking order if the pvt lock + * is held.*/ + sip_pvt_unlock(p); ast_channel_update_redirecting(current.chan2, &redirecting, &update_redirecting); ast_party_redirecting_free(&redirecting); - /* Do not hold the pvt lock during the indicate and async_goto. Those functions - * lock channels which will invalidate locking order if the pvt lock is held.*/ /* For blind transfers, move the call to the new extensions. For attended transfers on multiple * servers - generate an INVITE with Replaces. Either way, let the dial plan decided * indicate before masquerade so the indication actually makes it to the real channel * when using local channels with MOH passthru */ - sip_pvt_unlock(p); ast_indicate(current.chan2, AST_CONTROL_UNHOLD); res = ast_async_goto(current.chan2, refer_to_context, refer_to, 1);