summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2016-08-20 13:13:23 +0200
committermathieui <mathieui@mathieui.net>2016-08-20 13:13:23 +0200
commit11b193fb3614fb750c8abab1312f5c33cf9c0833 (patch)
tree5a7c1fa89ea05d56433e1dd9844becb3a45e4a5e
parent04939cc6c376c9de61e1eecb158c0f276c6bdf96 (diff)
downloadpoezio-11b193fb3614fb750c8abab1312f5c33cf9c0833.tar.gz
poezio-11b193fb3614fb750c8abab1312f5c33cf9c0833.tar.bz2
poezio-11b193fb3614fb750c8abab1312f5c33cf9c0833.tar.xz
poezio-11b193fb3614fb750c8abab1312f5c33cf9c0833.zip
Fix #3219, Fix #3220 (no connection loops on some stream errors)
Do not reconnect if the stream error is a conflict or an host-unknown; also add a sleep(1) in order to not DoS the server if it loops on other conditions.
-rw-r--r--poezio/core/core.py1
-rw-r--r--poezio/core/handlers.py14
2 files changed, 12 insertions, 3 deletions
diff --git a/poezio/core/core.py b/poezio/core/core.py
index bcc64d1a..e4f4687d 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -62,6 +62,7 @@ class Core(object):
# of being displayed on the screen and exiting the program.
sys.excepthook = self.on_exception
self.connection_time = time.time()
+ self.last_stream_error = None
self.stdscr = None
status = config.get('status')
status = POSSIBLE_SHOW.get(status, None)
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index 484f7378..e1e3b4b1 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -901,6 +901,7 @@ class HandlerCore:
"""
self.core.information("Connection to remote server failed: %s" % (error,), 'Error')
+ @asyncio.coroutine
def on_disconnected(self, event):
"""
When we are disconnected from remote server
@@ -913,9 +914,14 @@ class HandlerCore:
tab.disconnect()
msg_typ = 'Error' if not self.core.legitimate_disconnect else 'Info'
self.core.information("Disconnected from server.", msg_typ)
- if not self.core.legitimate_disconnect and config.get('auto_reconnect', True):
- self.core.information("Auto-reconnecting.", 'Info')
- self.core.xmpp.start()
+ if self.core.legitimate_disconnect or not config.get('auto_reconnect', True):
+ return
+ if (self.core.last_stream_error and
+ self.core.last_stream_error[1]['condition'] in ('conflict', 'host-unknown')):
+ return
+ yield from asyncio.sleep(1)
+ self.core.information("Auto-reconnecting.", 'Info')
+ self.core.xmpp.start()
def on_stream_error(self, event):
"""
@@ -923,6 +929,8 @@ class HandlerCore:
"""
if event and event['text']:
self.core.information('Stream error: %s' % event['text'], 'Error')
+ if event:
+ self.core.last_stream_error = (time.time(), event)
def on_failed_all_auth(self, event):
"""