fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

Sleekxmpp client (sleekxmpp.xmlstream.xmlstream) trying to resolve DNS for ejabberd server infinitely (not getting stopped, nor throwing error) upon device reboot. #416

Open chigurupati opened 8 years ago

chigurupati commented 8 years ago

Hello, I am running a component made of sleekxmpp to talk to underlying device or server. But when the device reboot's the sleekxmpp client tries to resolve the dns but it is not been able to resolve, thus waiting indefinitely. as it is shown in the below logs:

sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 6120: Stream Feature: STARTTLS sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 6120: Stream Feature: Resource Binding sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 3920: Stream Feature: Start Session sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 6121: Stream Feature: Roster Versioning sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 6121: Stream Feature: Subscription Pre-Approval sleekxmpp.plugins.base - DEBUG - Loaded Plugin: RFC 6120: Stream Feature: SASL sleekxmpp.plugins.base - DEBUG - Loaded Plugin: XEP-0030: Service Discovery sleekxmpp.plugins.base - DEBUG - Loaded Plugin: XEP-0004: Data Forms sleekxmpp.plugins.base - DEBUG - Loaded Plugin: XEP-0045: Multi-User Chat sleekxmpp.plugins.base - DEBUG - Loaded Plugin: XEP-0199: XMPP Ping sleekxmpp.plugins.base - DEBUG - Loaded Plugin: XEP-0249: Direct MUC Invitations sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying SRV records for x.y.z sleekxmpp.xmlstream.resolver - DEBUG - DNS: SRV record resolution timed out for x.y.z. sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying x.y.z for AAAA records. DEBUG - DNS: AAAA record resolution timed out for x.y.z sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying x.y.z for A records. sleekxmpp.xmlstream.resolver - DEBUG - DNS: A record resolution timed out for x.y.z sleekxmpp.xmlstream.xmlstream - DEBUG - No remaining DNS records to try. sleekxmpp.xmlstream.xmlstream - DEBUG - Waiting 2.10223447405 seconds before connecting. sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying SRV records for x.y.z sleekxmpp.xmlstream.resolver - DEBUG - DNS: SRV record resolution timed out for x.y.z. sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying x.y.z for AAAA records. sleekxmpp.xmlstream.resolver - DEBUG - DNS: AAAA record resolution timed out for x.y.z sleekxmpp.xmlstream.resolver - DEBUG - DNS: Querying x.y.z for A records. sleekxmpp.xmlstream.resolver - DEBUG - DNS: A record resolution timed out for x.y.z sleekxmpp.xmlstream.xmlstream - DEBUG - No remaining DNS records to try. sleekxmpp.xmlstream.xmlstream - DEBUG - Waiting 4.2563900779 seconds before connecting.

I don't no why it is not able to resolve dns upon reboot of the device. I am running the component on APU (Debian stretch). Please help me to resolve this issue.

Regards, Amarnath

XRevan86 commented 8 years ago
--- a/sleekxmpp/xmlstream/resolver.py
+++ b/sleekxmpp/xmlstream/resolver.py
@@ -175,6 +175,9 @@ def get_A(host, resolver=None, use_dnspy
     """
     log.debug("DNS: Querying %s for A records." % host)

+    if isinstance(host, bytes):
+        host = host.decode("utf-8")
+
     # If not using dnspython, attempt lookup using the OS level
     # getaddrinfo() method.
     if resolver is None or not use_dnspython:
@@ -189,7 +192,10 @@ def get_A(host, resolver=None, use_dnspy
     # Using dnspython:
     try:
         recs = resolver.query(host, dns.rdatatype.A)
-        return [rec.to_text() for rec in recs]
+        if isinstance(recs[0].to_text(), bytes):
+            return [rec.to_text().decode("utf-8") for rec in recs]
+        else:
+            return [rec.to_text() for rec in recs]
     except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
         log.debug("DNS: No A records for %s" % host)
         return []
@@ -222,6 +228,9 @@ def get_AAAA(host, resolver=None, use_dn
     """
     log.debug("DNS: Querying %s for AAAA records." % host)

+    if isinstance(host, bytes):
+        host = host.decode("utf-8")
+
     # If not using dnspython, attempt lookup using the OS level
     # getaddrinfo() method.
     if resolver is None or not use_dnspython:
@@ -240,7 +249,10 @@ def get_AAAA(host, resolver=None, use_dn
     # Using dnspython:
     try:
         recs = resolver.query(host, dns.rdatatype.AAAA)
-        return [rec.to_text() for rec in recs]
+        if isinstance(recs[0].to_text(), bytes):
+            return [rec.to_text().decode("utf-8") for rec in recs]
+        else:
+            return [rec.to_text() for rec in recs]
     except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
         log.debug("DNS: No AAAA records for %s" % host)
         return []
@@ -324,6 +336,8 @@ def get_SRV(host, port, service, proto='
                 if running_sum >= selected:
                     rec = sums[running_sum]
                     host = rec.target.to_text()
+                    if isinstance(host, bytes):
+                        host = host.decode("utf-8")
                     if host.endswith('.'):
                         host = host[:-1]
                     sorted_recs.append((host, rec.port))
bear commented 8 years ago

@XRevan86 any chance you could make a PR for this?