Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions gateway/platforms/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ async def _handle_polling_conflict(self, error: Exception) -> None:
# giving up, so the old session has time to expire.
self._polling_conflict_count += 1

MAX_CONFLICT_RETRIES = 3
RETRY_DELAY = 10 # seconds
MAX_CONFLICT_RETRIES = 5
RETRY_DELAY = 20 # seconds

if self._polling_conflict_count <= MAX_CONFLICT_RETRIES:
logger.warning(
Expand Down Expand Up @@ -864,7 +864,7 @@ async def _handle_polling_conflict(self, error: Exception) -> None:
% MAX_CONFLICT_RETRIES
)
logger.error("[%s] %s Original error: %s", self.name, message, error)
self._set_fatal_error("telegram_polling_conflict", message, retryable=False)
self._set_fatal_error("telegram_polling_conflict", message, retryable=True)
try:
if self._app and self._app.updater:
await self._app.updater.stop()
Expand Down
10 changes: 5 additions & 5 deletions tests/gateway/test_telegram_conflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ async def failing_start_polling(**kwargs):

# Directly call _handle_polling_conflict to avoid event-loop scheduling
# complexity. Each call simulates one 409 from Telegram.
for i in range(4):
for i in range(6):
await adapter._handle_polling_conflict(
conflict("Conflict: terminated by other getUpdates request")
)

# After 3 failed retries (count 1-3 each enter the retry branch but
# start_polling raises), the 4th conflict pushes count to 4 which
# exceeds MAX_CONFLICT_RETRIES (3), entering the fatal branch.
# After 5 failed retries (count 1-5 each enter the retry branch but
# start_polling raises), the 6th conflict pushes count to 6 which
# exceeds MAX_CONFLICT_RETRIES (5), entering the fatal branch.
assert adapter.fatal_error_code == "telegram_polling_conflict", (
f"Expected fatal after 4 conflicts, got code={adapter.fatal_error_code}, "
f"Expected fatal after 6 conflicts, got code={adapter.fatal_error_code}, "
f"count={adapter._polling_conflict_count}"
)
assert adapter.has_fatal_error is True
Expand Down