Summary:ASTERISK-17998: Hangup with active AGI connection does not work
Reporter:Ben Klang (bklang)Labels:
Date Opened:2011-06-12 15:52:26Date Closed:
Status:Open/NewComponents:Channels/chan_sip/General Resources/res_agi
Versions:10 1.8.4 13.18.4 Frequency of
is related toASTERISK-18233 Asterisk does not continue AGI code execution after the channel is hungup by caller.
Environment:Attachments:( 0) dialplan.rb
( 1) hangup-without-bye.pcap
Description:While a call is connected to an AGI socket, Asterisk does not hang up the channel when requested.  This is easy to reproduce, and was observed on both Asterisk 1.8 and trunk built this afternoon.

Steps to reproduce:
1) Create an AGI application that answers the line, and then hangs up, but does not exit or close the socket.  I have attached a dialplan.rb for Adhearsion that illustrates the issue.

2) Using wireshark or tcpdump, capture the SIP exchange.

3) Using a SIP client, dial an Asterisk extension that connects to Adhearsion via AGI.

When the script runs, it will answer the line, play "beep", and then tell Asterisk to hangup.  It then sleeps for 1 hour, leaving the AGI socket open.  In the packet capture, you will find that no SIP BYE is sent and the call remains active in the softphone.

Also attached to this ticket is a PCAP illustrating the issue.

Additional note: the hangup "works" in that additional AGI commands receive a "511 Command not permitted on a dead channel."  So Asterisk considers the channel hung up, but does not actually inform the far end.
Comments:By: Ben Klang (bklang) 2011-06-12 15:53:41.430-0500

pcap file of SIP and AGI session where a BYE is not sent on hangup request.

By: Ben Klang (bklang) 2011-06-12 15:54:18.967-0500

Adhearsion dialplan.rb showing how I produced this error.

By: Russell Bryant (russell) 2011-06-14 19:42:35.026-0500

I believe this is actually the expected behavior.  The actual hangup is not going to happen until the AGI() application exits.  The connection isn't dropped to allow any final cleanup the AGI application might want to perform.

Did this work differently on earlier versions of Asterisk?

By: Ben Klang (bklang) 2011-06-23 09:35:39.553-0500

I'm not sure, but I suspect that the current behavior is the same as older versions.  However, I still consider it a bug for the following reasons:

1) Most importantly, when I ask a channel to Hangup, I expect that it is in fact hung up.  This has implications on CDRs which can be used for billing.  When I tell a call to Hangup, and then need to do post-call processing that takes 30 seconds, the resulting CDR is 30 seconds longer than I should reasonably expect.  The way Hangup works now, it's more like a request to hang up the channel as soon as the AGI process closes the socket, which doesn't make sense.

2) From a technical perspective, it does make sense to keep the channel available (albeit in a dead state) for the AGI script to have limited interaction with it.  But it does not make sense to leave the endpoint connected.  Since we can signal a hangup, we should, even if we do not de-allocate the channel inside Asterisk until the socket disconnects.

By: dovid (dovid) 2011-12-28 06:30:30.778-0600


I kind of agree with Ben if I ask for a call to be hung up then it should be hung up on. Any clean ups (i.e. accounting) should be done in the h extension (if your asking me). I tested this with 10.0 and got the same result as Ben. Maybe we can have a happy medium where something is set in the agi to hangup if hangup is used in the AGI.

1) I tested on and it hangs up right away. Seems to have changed in 1.8.X some where.
2) A channel request hangup of the channel does not work. Asterisk will show that there is a request for the channel to be hung up on and then it waits till the agi exits.

By: dovid (dovid) 2012-02-07 22:55:06.468-0600


In what version of Asterisk did it work correctly for you? I am testing in and it's acting the same way (I can't seem to find the server that I tested it on).

By: Ben Klang (bklang) 2012-02-13 14:00:37.038-0600

Dovid, I'm not sure it ever worked "right", even in previous versions.  But, for the reasons I gave above, I still consider it a bug.  I have not tested for this issue prior to 1.6.2.

By: Richard Mudgett (rmudgett) 2012-02-13 15:09:47.928-0600

I think this reviewboard patch is intended for this issue:

By: Ben Klang (bklang) 2012-02-13 15:14:34.583-0600

That approach might work for some people, but is a little different from the issue I am reporting.

What I want to happen is for my AGI "HANGUP" command to actually signal a Hangup on the channel in question (in SIP terms, send a BYE to the remote party), and I want the CDR marked with the appropriate call end timestamp.  I do not necessarily want my AGI connection to Asterisk terminated, as there are some valuable reasons to keep that open (accessing former channel variables like DIALSTATUS, for example).  The reviewboard link might effect both of those things, but would come with the ugly side-effect of me losing my connection to Asterisk prematurely.

By: Russell Bryant (russell) 2012-02-13 18:33:24.393-0600

Agreed.  This patch isn't intended to provide the behavior Ben is looking for.  What Ben is looking for is reasonable and would be a nice addition, but it's not exactly trivial to implement.  AGI has never worked that way before.  I suppose it would technically be a new feature, but a good one, so I wouldn't close out this bug.