From 3f41fdd231998aeb68a7490f723d3c092bd7e380 Mon Sep 17 00:00:00 2001 From: Tom Nichols Date: Thu, 13 May 2010 14:39:32 -0400 Subject: fixed SRV query - should use dns.rdatatype.SRV --- sleekxmpp/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py index 5ba38090..954ca996 100644 --- a/sleekxmpp/__init__.py +++ b/sleekxmpp/__init__.py @@ -31,6 +31,7 @@ from . import plugins srvsupport = True try: import dns.resolver + import dns.rdatatype except ImportError: srvsupport = False @@ -102,7 +103,8 @@ class ClientXMPP(basexmpp, XMLStream): else: logging.debug("Since no address is supplied, attempting SRV lookup.") try: - answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.server) + answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.domain, + dns.rdatatype.SRV ) except dns.resolver.NXDOMAIN: logging.debug("No appropriate SRV record found. Using JID server name.") else: -- cgit v1.2.3 From 898f96f26553f7702df20fd04fc7ae9befc72109 Mon Sep 17 00:00:00 2001 From: Tom Nichols Date: Mon, 28 Jun 2010 11:03:46 -0400 Subject: print the traceback if we can't load a plugin for some reason --- sleekxmpp/basexmpp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index b78c255c..ad737360 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -110,7 +110,7 @@ class basexmpp(object): xep = "(XEP-%s) " % self.plugin[plugin].xep logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description)) except: - logging.error("Unable to load plugin: %s" %(plugin) ) + logging.exception("Unable to load plugin: %s", plugin ) def register_plugins(self): """Initiates all plugins in the plugins/__init__.__all__""" -- cgit v1.2.3 From e8d37b409c0e29ebb6dcfac2651d5cedc07af965 Mon Sep 17 00:00:00 2001 From: Tom Nichols Date: Mon, 28 Jun 2010 11:04:18 -0400 Subject: make the scheduler a daemon thread to prevent hanging when the main thread exits. --- sleekxmpp/xmlstream/scheduler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sleekxmpp/xmlstream/scheduler.py b/sleekxmpp/xmlstream/scheduler.py index 40aaf695..e4df02d1 100644 --- a/sleekxmpp/xmlstream/scheduler.py +++ b/sleekxmpp/xmlstream/scheduler.py @@ -41,6 +41,7 @@ class Scheduler(object): def process(self, threaded=True): if threaded: self.thread = threading.Thread(name='shedulerprocess', target=self._process) + self.thread.daemon = True self.thread.start() else: self._process() -- cgit v1.2.3 From 15ac3e9fba8fe63b4de64564533d7269def9041e Mon Sep 17 00:00:00 2001 From: Tom Nichols Date: Mon, 28 Jun 2010 11:06:26 -0400 Subject: race condition where we were transitioning to 'disconnected' and immediately reconnecting in another thread before the socket.close call occurred. Now we're locking the state machine until the disconnect routine completes. --- sleekxmpp/xmlstream/xmlstream.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 6dbe7b30..b669a31d 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -59,7 +59,7 @@ class XMLStream(object): self.ssl_support = ssl_support self.escape_quotes = escape_quotes self.state = statemachine.StateMachine(('disconnected','connecting', - 'connected')) + 'connected')) self.should_reconnect = True self.setSocket(socket) @@ -240,7 +240,7 @@ class XMLStream(object): if self.should_reconnect: self.disconnect(reconnect=True) - logging.debug('Quitting Process thread') + logging.debug('Quitting Process thread') def __readXML(self): "Parses the incoming stream, adding to xmlin queue as it goes" @@ -302,23 +302,24 @@ class XMLStream(object): return True def disconnect(self, reconnect=False): - if not self.state.transition('connected','disconnected'): - logging.warning("Already disconnected.") - return - logging.debug("Disconnecting...") - self.sendRaw(self.stream_footer) - time.sleep(5) - #send end of stream - #wait for end of stream back - try: -# self.socket.shutdown(socket.SHUT_RDWR) - self.socket.close() - except socket.error as (errno,strerror): - logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror)) - try: - self.filesocket.close() - except socket.error as (errno,strerror): - logging.exception("Error closing filesocket.") + with self.state.transition_ctx('connected','disconnected') as locked: + if not locked: + logging.warning("Already disconnected.") + return + logging.debug("Disconnecting...") + self.sendRaw(self.stream_footer) + time.sleep(5) + #send end of stream + #wait for end of stream back + try: +# self.socket.shutdown(socket.SHUT_RDWR) + self.socket.close() + except socket.error as (errno,strerror): + logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror)) + try: + self.filesocket.close() + except socket.error as (errno,strerror): + logging.exception("Error closing filesocket.") if reconnect: self.connect() -- cgit v1.2.3