Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gateway/platforms/telegram_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async def handle_async_request(self, request: httpx.Request) -> httpx.Response:

sticky_ip = self._sticky_ip
attempt_order: list[Optional[str]] = [sticky_ip] if sticky_ip else [None]
if sticky_ip:
attempt_order.append(None) # retry primary DNS after sticky failure
for ip in self._fallback_ips:
if ip != sticky_ip:
attempt_order.append(ip)
Expand All @@ -99,6 +101,14 @@ async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
last_error = exc
if not _is_retryable_connect_error(exc):
raise
if ip is not None and ip == self._sticky_ip:
async with self._sticky_lock:
if self._sticky_ip == ip:
self._sticky_ip = None
logger.warning(
"[Telegram] Sticky fallback IP %s failed; resetting to primary DNS path",
ip,
)
if ip is None:
logger.warning(
"[Telegram] Primary api.telegram.org connection failed (%s); trying fallback IPs %s",
Expand Down