mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-26 02:57:04 +00:00
all DNS queries should have a timeout, fixes #591
This commit is contained in:
parent
2b351208e0
commit
1926bfa1c5
@ -794,6 +794,7 @@ def set_custom_dns_record(qname, rtype, value, action, env):
|
|||||||
|
|
||||||
def get_secondary_dns(custom_dns, mode=None):
|
def get_secondary_dns(custom_dns, mode=None):
|
||||||
resolver = dns.resolver.get_default_resolver()
|
resolver = dns.resolver.get_default_resolver()
|
||||||
|
resolver.timeout = 10
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
for qname, rtype, value in custom_dns:
|
for qname, rtype, value in custom_dns:
|
||||||
@ -826,11 +827,12 @@ def set_secondary_dns(hostnames, env):
|
|||||||
if len(hostnames) > 0:
|
if len(hostnames) > 0:
|
||||||
# Validate that all hostnames are valid and that all zone-xfer IP addresses are valid.
|
# Validate that all hostnames are valid and that all zone-xfer IP addresses are valid.
|
||||||
resolver = dns.resolver.get_default_resolver()
|
resolver = dns.resolver.get_default_resolver()
|
||||||
|
resolver.timeout = 5
|
||||||
for item in hostnames:
|
for item in hostnames:
|
||||||
if not item.startswith("xfr:"):
|
if not item.startswith("xfr:"):
|
||||||
# Resolve hostname.
|
# Resolve hostname.
|
||||||
try:
|
try:
|
||||||
response = dns.resolver.query(item, "A")
|
response = resolver.query(item, "A")
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
raise ValueError("Could not resolve the IP address of %s." % item)
|
raise ValueError("Could not resolve the IP address of %s." % item)
|
||||||
else:
|
else:
|
||||||
|
@ -594,6 +594,9 @@ def query_dns(qname, rtype, nxdomain='[Not Set]', at=None):
|
|||||||
resolver = dns.resolver.Resolver()
|
resolver = dns.resolver.Resolver()
|
||||||
resolver.nameservers = [at]
|
resolver.nameservers = [at]
|
||||||
|
|
||||||
|
# Set a timeout so that a non-responsive server doesn't hold us back.
|
||||||
|
resolver.timeout = 5
|
||||||
|
|
||||||
# Do the query.
|
# Do the query.
|
||||||
try:
|
try:
|
||||||
response = resolver.query(qname, rtype)
|
response = resolver.query(qname, rtype)
|
||||||
|
Loading…
Reference in New Issue
Block a user