Let's say I'm writing HTTP requests in Python and my DNS server goes down.
If I try:
import requests
requests.get('https://api.twilio.com', timeout=3)
and the DNS server is down, this can take upwards of 90 seconds, despite specifying a timeout value.
Furthermore the blocking call is socket.getaddrinfo
, and it doesn't look like this takes a timeout parameter.
Is there a way to set a timeout on the DNS lookup?
There is no way to pass a timeout to the getaddrinfo system call, because it does not accept a timeout argument. You can run the lookup in a thread, and then cancel it if it expires.
On Unix machines, you can modify /etc/resolv.conf
to set a timeout for addrinfo lookups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With