[Home]

Summary:ASTERISK-05976: [patch] timeout dial plan loop
Reporter:Peng Yong (ppyy)Labels:
Date Opened:2006-01-04 08:37:21.000-0600Date Closed:2011-06-07 14:10:45
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Functions/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) patch.maxtimeout
( 1) patch.maxtimeout.2
( 2) patch.maxtimeout.3
( 3) patch.maxtimeout.4
( 4) patch.maxtimeout.5
Description:asterisk will loop forever if a SIP client crash in following dialplan:

exten => 3100,1,Wait,1                    
exten => 3100,n,Answer
exten => 3100,n,Set(TIMEOUT(digit)=5)      
exten => 3100,n,Set(TIMEOUT(response)=10)  
exten => 3100,n(restart),BackGround(invalid)
exten => 3100,n,WaitExten

exten => t,1,Goto(3100,restart)

i found there is a SIP channel loops for about 12 hours in the dialplan, not exit.

here is a patch to set maxtimeout times.

default 3, can be set by:

exten => 3100,n,WaitExten(||5)

Comments:By: Russell Bryant (russell) 2006-01-04 22:51:44.000-0600

It doesn't make much sense to accept any more new options to applications without using the new application argument parsing macros.  See many of the applications in the apps/ directory for examples on how to use them.

By: Tilghman Lesher (tilghman) 2006-01-04 22:55:10.000-0600

And why not just set TIMEOUT(absolute) to something?

By: Peng Yong (ppyy) 2006-01-05 05:56:53.000-0600

update by argument parsing macros.

corydon76: some time we can't set absolute timeout properly, user will be hangup if it is too short. and it will be in the loop if some one don't set absolute timeout.

By: Peng Yong (ppyy) 2006-01-05 06:02:47.000-0600

sorry, forgot to remove some debug lines. upload again

By: Peng Yong (ppyy) 2006-01-06 02:16:17.000-0600

minor change. reset maxtimeout if user press a key.

By: Mark Spencer (markster) 2006-01-07 17:19:16.000-0600

You can already do this with a while loop:

exten => 3100,1,Set(count=0)
exten => 3100,n,While($[${count} < 3])
exten => 3100,n,Set(count=$[${count} + 1])
exten => 3100,n,Background(invalid)
exten => 3100,n,WaitExten
exten => 3100,n,EndWhile

Furthermore, you can also use "rtptimeout" in Asterisk...

By: Peng Yong (ppyy) 2006-01-09 09:34:18.000-0600

markster: rtptimeout is a trick to end loop. while in IRV menu, i prefer to stop user after several timeout and say good bye to him.

while/endwhile also can avoid loop, but it also don't jump to 't' when timeout. 't' is very usefull in IRV menu to prompt user.

how can i do it in IRV menu:

if timeout , say some prompt to him, after 2 time out, say good bye to hime and hangup. but with "exten => 3100,n,Playback(goodbye)", it will not goto 't'

exten => 3100,1,Wait,1
exten => 3100,n,Answer
exten => 3100,n,Set(TIMEOUT(digit)=5)
exten => 3100,n,Set(TIMEOUT(response)=10)
exten => 3100,n(restart),BackGround(invalid)
exten => 3100,n,WaitExten(3||2) ; max 2 timeout
exten => 3100,n,Playback(goodbye)

exten => t,1,Playback(prompt)
exten => t,n,Goto(3100,restart)

in pbx_builtin_waitexten function of pbx.c, if exist '+1' priority, it will run it instead of 't' extenstion. may we patch it to let 't' run first ?

if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, continuing...\n", chan->name);
} else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, going to 't'\n", chan->name);
ast_copy_string(chan->exten, "t", sizeof(chan->exten));
chan->priority = 0;
} else {
ast_log(LOG_WARNING, "Timeout but no rule 't' in context '%s'\n", chan->context);
res = -1;
}

By: Russell Bryant (russell) 2006-01-09 11:37:49.000-0600

The code you are referring to is exactly why the While loop will do what you need.

To say goodbye after 3 tries, you just add another priority ...

exten => 3100,1,Set(count=0)
exten => 3100,n,While($[${count} < 3])
exten => 3100,n,Set(count=$[${count} + 1])
exten => 3100,n,Background(invalid)
exten => 3100,n,WaitExten
exten => 3100,n,EndWhile
exten => 3100,n,Playback(goodbye)

By: Russell Bryant (russell) 2006-01-09 11:39:00.000-0600

I'm closing this out since there is already a very commonly used and reasonable way to do this.

If you have further questions, consult the asterisk-users mailing list or #asterisk on irc.freenode.net.

By: Russell Bryant (russell) 2006-01-09 11:41:03.000-0600

+1 karma for the contribution, anyway  :)