Skip to content

Commit 03f54e2

Browse files
authored
Fix wait second handling in proxy_with_retry (#137)
* Fix wait second handling in `proxy_with_retry` Adds new argument `max_wait_seconds` which actually was the broken behaviour of the previous `min_wait_seconds` which is now correctly handled. * Add `multiply_wait_seconds` argument
1 parent 741995e commit 03f54e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mautrix/util/proxy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ async def proxy_with_retry(
9090
proxy_handler: ProxyHandler,
9191
on_proxy_change: Callable[[], Awaitable[None]],
9292
max_retries: int = 10,
93-
min_wait_seconds: int = 60,
93+
min_wait_seconds: int = 0,
94+
max_wait_seconds: int = 60,
95+
multiply_wait_seconds: int = 10,
9496
retryable_exceptions: tuple[Exception] = RETRYABLE_PROXY_EXCEPTIONS,
9597
) -> T:
9698
errors = 0
@@ -102,7 +104,9 @@ async def proxy_with_retry(
102104
errors += 1
103105
if errors > max_retries:
104106
raise
105-
wait = min(errors * 10, min_wait_seconds)
107+
wait = errors * multiply_wait_seconds
108+
wait = max(wait, min_wait_seconds)
109+
wait = min(wait, max_wait_seconds)
106110
logger.warning(
107111
"%s while trying to %s, retrying in %d seconds",
108112
e.__class__.__name__,

0 commit comments

Comments
 (0)