From d85efec7a245fee045fdd095221ccfa9bd43b58f Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Mon, 23 Mar 2020 18:56:22 +0100 Subject: reconnect: fix callback when not currently connected The 'disconnected' event is normally fired from connection_lost(), which is called by the connection code when the connection is lost after being established. However, if the connection wasn't successfully established, a manual /reconnect no-ops because it waits for the 'disconnected' callback which never fires. This patch does two things: 1. Immediately fire a 'disconnected' event in disconnect() if there is no transport. 2. Register the 'disconnected' event handler in reconnect() *before* it can be fired. --- slixmpp/xmlstream/xmlstream.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index dbf515ca..c3c82a37 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -494,6 +494,8 @@ class XMLStream(asyncio.BaseProtocol): self.send_raw(self.stream_footer) self.schedule('Disconnect wait', wait, self.abort, repeat=False) + else: + self.event("disconnected", reason) def abort(self): """ @@ -512,8 +514,8 @@ class XMLStream(asyncio.BaseProtocol): when the server acknowledgement is received), call connect() """ log.debug("reconnecting...") - self.disconnect(wait, reason) self.add_event_handler('disconnected', lambda event: self.connect(), disposable=True) + self.disconnect(wait, reason) def configure_socket(self): """Set timeout and other options for self.socket. -- cgit v1.2.3