From f4e81d7a54f0c766457754667b66d0a6582b95b9 Mon Sep 17 00:00:00 2001
From: Olle Johansson <oej@edvina.net>
Date: Tue, 29 May 2007 16:17:17 +0000
Subject: [PATCH] Merged revisions 66404 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r66404 | oej | 2007-05-29 18:02:50 +0200 (Tue, 29 May 2007) | 2 lines

Tracking down hanging channels, killing them one by one. Issue #9235 and related

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66432 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_sip.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 981f694ba4..80a5424f9b 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2096,14 +2096,16 @@ static int retrans_pkt(void *data)
 			usleep(1);
 			sip_pvt_lock(pkt->owner);
 		}
+		if (pkt->owner->owner) 
+			pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE;
 		if (pkt->method == SIP_BYE) {
 			/* Ok, we're not getting answers on SIP BYE's. Who cares?
 		           let's take the call down anyway. */
-			if (pkt->owner->owner)
+			if (pkt->owner->owner) 
 				ast_channel_unlock(pkt->owner->owner);
 			append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway.");
 			ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);	
-		} if (pkt->owner->owner) {
+		} else if (pkt->owner->owner) {
 			sip_alreadygone(pkt->owner);
 			ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet.\n", pkt->owner->callid);
 			ast_queue_hangup(pkt->owner->owner);
@@ -2112,8 +2114,12 @@ static int retrans_pkt(void *data)
 			/* If no channel owner, destroy now */
 
 			/* Let the peerpoke system expire packets when the timer expires for poke_noanswer */
-			if (pkt->method != SIP_OPTIONS && pkt->method != SIP_REGISTER)
+			if (pkt->method != SIP_OPTIONS && pkt->method != SIP_REGISTER) {
 				ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);	
+				sip_alreadygone(pkt->owner);
+				if (option_debug)
+					append_history(pkt->owner, "DialogKill", "Killing this failed dialog immediately");
+			}
 		}
 	}
 	/* Remove the packet */
@@ -3768,6 +3774,8 @@ static int sip_hangup(struct ast_channel *ast)
 					/* We can't send anything in CALLING state */
 					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
 					/* Do we need a timer here if we don't hear from them at all? */
+					sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
+					append_history(p, "DELAY", "Not sending cancel, waiting for timeout");
 				} else {
 					/* Send a new request: CANCEL */
 					transmit_request(p, SIP_CANCEL, p->ocseq, XMIT_RELIABLE, FALSE);
-- 
GitLab