Joseph Tanner
2006-Mar-08 14:30 UTC
[Asterisk-Users] Any way to change dns timeout value? Asterisk hangs if internet unreachable
I don't have the most reliable internet connection in the world. Whenever it goes out, I can't receive any incoming calls at all, not even from pstn. When it first goes out I can still make outgoing calls through pstn, but eventually that fails too (as does voicemail, everything's out). Yes, asterisk and the local phones are all on the same network and can communicate fine. Ok, that's the symptom, and I believe I know what's causing it. Asterisk seems to be hanging on dns lookups. After a while, it gets so bad that it won't process anything at all. The reason incoming calls via pstn won't work is because I have a calleridname.agi script that runs as soon as a call comes in. Instead of trying for say, 5 seconds and then giving up, asterisk just sits there forever waiting for it to resolve. Once asterisk gives up, the caller has hung up ages ago. Obviously, I don't want pstn calls to be dependent on my internet connection, kinda defeats having a pstn line at all. Now, as soon as the internet connection craps out, I can still make outgoing calls via pstn, access voicemail, etc. If it's a long outage (like this morning, some fiber cut and the whole county is without internet, redundancy anyone?), eventually everything stops. I think it's because asterisk is re-trying to register with a host, before the dns timed out, and the built-up dns queries just bring the whole thing to a halt eventually. This morning after I noticed the internet connection was down, I tried to call the phone company (through the pstn line) and could not. When I watched the CLI, I noticed it try to call a minute or two after I hung up, quite a delayed reaction. Also could not access voicemail. When the connection came back up for a minute and crapped back out again, I was suddenly able to access voicemail and make a call. Shortly after that, I'd dial a number and it'd connect after 10 seconds or so. After that, it wouldn't try to connect until after the phone received a fast busy. A workaround was to backup my sip.conf and iax.conf files, then edit them taking out every single host reference that wasn't an ip address. If I left them in and tried to restart asterisk, it would hang on the first host trying to resolve. A minute or so later it'd give up and move on to the second. Obviously very bad news if you have several hosts that it needs to resolve (side note, why can't asterisk try to resolve multiple hosts at once; say one every 5 seconds, so it doesn't flood your network with dns requests, but also if one host hangs it can try resolving other hosts while waiting?). I've looked in dns.c and dnsmgr.c and can't see where I can set a timeout. Perhaps it's somewhere else? Maybe hiding in several files? Any ideas? I'd like to set it to five seconds, this should give most hosts that aren't down plenty of time to respond. Perhaps even better, I could cache dns results and save them to a file? Run a background application to query dns servers, if it hangs then asterisk uses the last good values (and if it's not reachable, no big deal, asterisk will just move on). I promise I searched on google before posting here. The closest thing I could find is this: http://bugs.digium.com/view.php?id=3946 Doesn't seem to have a real solution. Joseph Tanner
Olle E Johansson
2006-Mar-09 00:29 UTC
[Asterisk-Users] Any way to change dns timeout value? Asterisk hangs if internet unreachable
The real solution is to implement asynchronus DNS. We are looking into doing that with the C-ares library. No promises yet, it all depends on funding for this development work. If anyone is interested in funding it, please contact me off list. /O --- * Olle E. Johansson - oej@edvina.net * Asterisk Training http://edvina.net/training/