Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <cassidy@cass-wks.(none)>2007-11-14 12:28:50 (GMT)
committer Guillaume Desmottes <cassidy@cass-wks.(none)>2007-11-14 12:28:50 (GMT)
commit655569208b20abf5eaee77d5fdede1daae09667f (patch)
tree7fec9b52f2e2276384d4d06e2e50a700074e0596
parentb6ac5c857886bf5d2a9dd992b9c78adde0425a92 (diff)
Use an exponential backoff when trying to reconnect CM (#2522)
-rw-r--r--NEWS1
-rw-r--r--src/telepathy_plugin.py26
2 files changed, 18 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index dd4b1cf..0b8cebc 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,4 @@
+* #2522: Use an exponential backoff when trying to reconnect CM (cassidy)
* #4907: Try to reconnect Gabble if initial attempt failed (cassidy)
Snapshot 89c33bcf93
diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py
index 1a10c29..af1a327 100644
--- a/src/telepathy_plugin.py
+++ b/src/telepathy_plugin.py
@@ -36,7 +36,6 @@ from telepathy.interfaces import (CONN_INTERFACE, CHANNEL_TYPE_TEXT,
CONN_INTERFACE_ALIASING, CHANNEL_TYPE_CONTACT_LIST,
CONN_MGR_INTERFACE)
-
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
@@ -76,7 +75,8 @@ class TelepathyPlugin(gobject.GObject):
(gobject.SIGNAL_RUN_FIRST, None, [object]),
}
- _RECONNECT_TIMEOUT = 5000
+ _RECONNECT_INITIAL_TIMEOUT = 5000 # 5 seconds
+ _RECONNECT_MAX_TIMEOUT = 300000 # 5 minutes
_TP_CONN_MANAGER = 'gabble'
_PROTOCOL = 'jabber'
@@ -120,6 +120,9 @@ class TelepathyPlugin(gobject.GObject):
#: GLib source ID indicating when we may try to reconnect
self._backoff_id = 0
+ #: length of the next reconnect timeout
+ self._reconnect_timeout = self._RECONNECT_INITIAL_TIMEOUT
+
#: Parameters for the connection manager
self._account = self._get_account_info()
@@ -177,6 +180,16 @@ class TelepathyPlugin(gobject.GObject):
return False
+ def _reset_reconnect_timer(self):
+ if self._backoff_id != 0:
+ gobject.source_remove(self._backoff_id)
+
+ self._backoff_id = gobject.timeout_add(self._reconnect_timeout,
+ self._reconnect_cb)
+
+ if self._reconnect_timeout < self._RECONNECT_MAX_TIMEOUT:
+ self._reconnect_timeout *= 2
+
def _init_connection(self):
"""Set up our connection
@@ -212,10 +225,7 @@ class TelepathyPlugin(gobject.GObject):
def connect_error(e):
_logger.debug('%r: Connect() failed: %s', self, e)
# we don't allow ourselves to retry more often than this
- if self._backoff_id != 0:
- gobject.source_remove(self._backoff_id)
- self._backoff_id = gobject.timeout_add(self._RECONNECT_TIMEOUT,
- self._reconnect_cb)
+ self._reset_reconnect_timer()
self._conn = None
self._conn[CONN_INTERFACE].Connect(reply_handler=connect_reply,
@@ -275,9 +285,7 @@ class TelepathyPlugin(gobject.GObject):
# this timer is running also serves as a marker to indicate
# that we shouldn't try to go back online yet.
if self._backoff_id:
- gobject.source_remove(self._backoff_id)
- self._backoff_id = gobject.timeout_add(self._RECONNECT_TIMEOUT,
- self._reconnect_cb)
+ self._reset_reconnect_timer()
self.emit('status', self._conn_status, int(reason))