How to let net.LookupMX timeout?

134 views
Skip to first unread message

Googol Lee

unread,
Nov 15, 2012, 1:12:07 AM11/15/12
to golan...@googlegroups.com
Recently Great Firewall in China is more powerful and pollute Google Domain. When try to net.LookupMX("gmail.com"), it may halt a long time and no return.

Is there a way to let net.LookupMX timeout? Although it won't block the other request, I hope it can release after a while and receive a timeout error.

And, net.smtp doesn't have timeout.

Kamil Kisiel

unread,
Nov 15, 2012, 2:04:44 AM11/15/12
to golan...@googlegroups.com
It seems the Lookup functions all get their options from /etc/resolv.conf (at least on unix, I'm not familiar with how this stuff works on Windows). 

You should be able to add a line that says

options timeout:n

to /etc/resolv.conf to change the timeout. There's also numerous other options which may be useful in speeding up your DNS resolution, check man 5 resolver or man 5 resolv.conf.

Googol Lee

unread,
Nov 15, 2012, 2:19:12 AM11/15/12
to golan...@googlegroups.com
Thanks for rapid reply. It's helpful.

Martin Kühl

unread,
Nov 15, 2012, 2:09:28 AM11/15/12
to Googol Lee, golan...@googlegroups.com
There is a very nice example and description of adding timeouts here:
https://gobyexample.com/timeouts
> --
>
>
Reply all
Reply to author
Forward
0 new messages