]> jfr.im git - irc/rizon/acid.git/commitdiff
Catch timeout exceptions and decrease the default timeout value
authorlinostar <redacted>
Wed, 1 Jun 2016 21:06:20 +0000 (21:06 +0000)
committerlinostar <redacted>
Sun, 19 Jun 2016 21:24:09 +0000 (21:24 +0000)
pyva/pyva/src/main/python/moo/requests.py

index 34160ebc14f7d0e9097783f4efc9d531522f4b00..650bd4d3841db374d002f3306437c7d14492d116 100644 (file)
@@ -346,7 +346,15 @@ class RequestManager(object):
                        return (False, reason, int)
                
                is_resolvable, resolved, host = self.__is_resolvable(vhost)
-               txt_record_exists = self.check_nick_in_TXT_records(vhost, nick)
+               (txt_record_exists, resolving_error) = self.check_nick_in_TXT_records(vhost, nick)
+
+               if resolving_error == "timeout":
+                       self.module.msg(self.module.chan, "DNS Timeout when trying to check TXT record for vhost @b{}@b requested by @b{}@b.".format(
+                               vhost, nick))
+               elif resolving_error:
+                       self.module.msg(self.module.chan, "The following error occured when checking TXT record for vhost @b{}@b requested by @b{}@b @sep {}.".format(
+                               vhost, nick, resolving_error))
+
                if is_resolvable and not txt_record_exists:
                        return (False, 
                                'Your vHost resolves. You can add a particular DNS TXT record to confirm the ownership of the domain and request again. %s' % RULES, 
@@ -399,16 +407,22 @@ class RequestManager(object):
                return False
 
        def check_nick_in_TXT_records(self, host, nick):
-               DNS.ParseResolvConf()
-               dns_req = DNS.DnsRequest(name=host, qtype='TXT')
-               res = dns_req.req()
-               for answer in res.answers:
-                       if 'data' in answer and (isinstance(answer['data'], list) or isinstance(answer['data'], tuple)):
-                               for entry in answer['data']:
-                                       parts = entry.split('=')
-                                       if len(parts) > 1 and parts[0].lower().strip() == 'rizon_vhost':
-                                               if parts[1].strip() == '*':
-                                                       return True
-                                               nicks = [n.lower().strip() for n in parts[1].split(',')]
-                                               if nick.lower() in nicks:
-                                                       return True
+               try:
+                       DNS.ParseResolvConf()
+                       dns_req = DNS.DnsRequest(name=host, qtype='TXT', timeout=10)
+                       res = dns_req.req()
+                       for answer in res.answers:
+                               if 'data' in answer and (isinstance(answer['data'], list) or isinstance(answer['data'], tuple)):
+                                       for entry in answer['data']:
+                                               parts = entry.split('=')
+                                               if len(parts) > 1 and parts[0].lower().strip() == 'rizon_vhost':
+                                                       if parts[1].strip() == '*':
+                                                               return (True, "")
+                                                       nicks = [n.lower().strip() for n in parts[1].split(',')]
+                                                       if nick.lower() in nicks:
+                                                               return (True, "")
+                       return (False, "")
+               except DNS.TimeoutError, e:
+                       return (False, "timeout")
+               except Exception, e:
+                       return (False, str(e))