Skip to content

Commit 06ba97e

Browse files
authored
Fix bad_sync_timeout to be a reasonable starting value (#184)
Also make bad_sync_timeout into a kwarg just in case. Signed-off-by: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
1 parent b544a46 commit 06ba97e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

matrix_client/client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def listen_for_events(self, timeout_ms=30000):
411411
"""
412412
self._sync(timeout_ms)
413413

414-
def listen_forever(self, timeout_ms=30000, exception_handler=None):
414+
def listen_forever(self, timeout_ms=30000, exception_handler=None,
415+
bad_sync_timeout=5):
415416
""" Keep listening for events forever.
416417
417418
Args:
@@ -420,21 +421,23 @@ def listen_forever(self, timeout_ms=30000, exception_handler=None):
420421
exception_handler (func(exception)): Optional exception handler
421422
function which can be used to handle exceptions in the caller
422423
thread.
424+
aad_sync_timeout (int): Base time to wait after an error before
425+
retrying. Will be increased according to exponential backoff.
423426
"""
424-
bad_sync_timeout = 5000
427+
_bad_sync_timeout = bad_sync_timeout
425428
self.should_listen = True
426429
while (self.should_listen):
427430
try:
428431
self._sync(timeout_ms)
429-
bad_sync_timeout = 5
432+
_bad_sync_timeout = bad_sync_timeout
430433
except MatrixRequestError as e:
431434
logger.warning("A MatrixRequestError occured during sync.")
432435
if e.code >= 500:
433436
logger.warning("Problem occured serverside. Waiting %i seconds",
434437
bad_sync_timeout)
435438
sleep(bad_sync_timeout)
436-
bad_sync_timeout = min(bad_sync_timeout * 2,
437-
self.bad_sync_timeout_limit)
439+
_bad_sync_timeout = min(_bad_sync_timeout * 2,
440+
self.bad_sync_timeout_limit)
438441
elif exception_handler is not None:
439442
exception_handler(e)
440443
else:

0 commit comments

Comments
 (0)