fix(telegram): increase cold-boot retry budget and cap backoff
Bump connect retry attempts from 3 to 8 and cap exponential backoff at 15 seconds. Old budget: 3 attempts, 1+2+4=7s total — insufficient for cold boot on slow networks or embedded devices. New budget: 8 attempts, 1+2+4+8+15+15+15=~60s total. Inspired by PR #5770 by @Bartok9 (re-implemented against current main since original was 913 commits stale with conflicts).
This commit is contained in:
@@ -665,14 +665,14 @@ class TelegramAdapter(BasePlatformAdapter):
|
|||||||
from telegram.error import NetworkError, TimedOut
|
from telegram.error import NetworkError, TimedOut
|
||||||
except ImportError:
|
except ImportError:
|
||||||
NetworkError = TimedOut = OSError # type: ignore[misc,assignment]
|
NetworkError = TimedOut = OSError # type: ignore[misc,assignment]
|
||||||
_max_connect = 3
|
_max_connect = 8
|
||||||
for _attempt in range(_max_connect):
|
for _attempt in range(_max_connect):
|
||||||
try:
|
try:
|
||||||
await self._app.initialize()
|
await self._app.initialize()
|
||||||
break
|
break
|
||||||
except (NetworkError, TimedOut, OSError) as init_err:
|
except (NetworkError, TimedOut, OSError) as init_err:
|
||||||
if _attempt < _max_connect - 1:
|
if _attempt < _max_connect - 1:
|
||||||
wait = 2 ** _attempt
|
wait = min(2 ** _attempt, 15)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"[%s] Connect attempt %d/%d failed: %s — retrying in %ds",
|
"[%s] Connect attempt %d/%d failed: %s — retrying in %ds",
|
||||||
self.name, _attempt + 1, _max_connect, init_err, wait,
|
self.name, _attempt + 1, _max_connect, init_err, wait,
|
||||||
|
|||||||
Reference in New Issue
Block a user