[asterisk-users] AGI perl script set timeout within script?

Olle E. Johansson oej at edvina.net
Fri Jan 8 02:09:45 CST 2010


8 jan 2010 kl. 08.01 skrev Tilghman Lesher:

> On Thursday 07 January 2010 21:17:52 JR Richardson wrote:
>> On Thu, 7 Jan 2010, Tilghman Lesher wrote:
>>> On Thu, Jan 7, 2010 at 6:27 PM, JR Richardson wrote:
>>>> problem I'm running into is if the DNS server is not responding, the
>>>> script hangs and waits for 30 seconds before returning to the
>>>> Asterisk dialplan. ?I would like a timeout of 1 second, then return.
>>> 
>>> Ah, but Perl isn't actually doing the DNS lookup.  If you examine his
>>> script, he's merely passing back a name to the Asterisk process, which
>>> is then calling inet_aton(), which is the reason why he cannot control
>>> it from within the script.  What he'd actually need to do is to start
>>> using Net::DNS to do the resolution on that name, first, perhaps even
>>> going as far as to connect to the server himself, and relay the channel
>>> between the AGI interface and the remote TCP interface.
>>> 
>>> Then, he could use alarm() or the Time::Hires module to ensure his own
>>> timeouts override the builtins.  But as it stands now, it's all
>>> Asterisk.
>> 
>> I tried the perl script eval, alarm,
>> $SIG{ALRM} functions till I was blue in the face from cussing at the
>> screen. It does not appear that the perl script is doing the DNS query,
>> otherwise the eval alarm would timeout and pass control back to asterisk. 
>> Another indication is that '#define MAX_AGI_CONNECT 2000' in res_agi is not
>> being invoked because the timeout is around 30 seconds.  Is that 30 second
>> timeout built into Asterisk?  Can I put an absolute timeout on an agi
>> script from the dialplan prior to calling the agi application?  Maybe I'll
>> fork a macro with a timeout, yea, that's it, let start forking, something
>> new to cuss at.
> 
> No, the timeout is built into glibc.  I don't see any documented method for
> altering it, sorry.  The only way to really do it in a way where you can
> control the timeouts would be to do it in your Perl script, in the way that I
> described above.

Earlier in this thread the settings in resolv.conf was mentioned, which is where you normally configure the local resolver, unless you bypass it somehow. From the linux man page:

"options timeout:n
sets the amount of time the resolver will wait for a response from a remote name server before retrying the query via a different name server. Measured in seconds, the default is RES_TIMEOUT (currently 5, see <resolv.h>).

options attempts:n
sets the number of times the resolver will send a query to its name servers before giving up and returning an error to the calling application. The default is RES_DFLRETRY (currently 2, see <resolv.h>)."

So the timeout depends on the numbers of servers in resolv.conf and the number of attempts per server multiplied with the timeout - if I understand it correctly.

/O


More information about the asterisk-users mailing list