fix: Telegram 409 감지 시 백오프 대신 polling 즉시 종료 (#180)
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
409 충돌 감지 시 30초 백오프 후 재시도하는 방식에서 _running = False로 polling을 즉시 중단하는 방식으로 변경. 다중 인스턴스가 실행 중인 경우 재시도는 의미 없고 충돌만 반복됨. 이제 409 발생 시 이 프로세스의 Telegram 명령어 polling을 완전히 비활성화. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -516,7 +516,6 @@ class TelegramCommandHandler:
|
||||
self._last_update_id = 0
|
||||
self._polling_task: asyncio.Task[None] | None = None
|
||||
self._running = False
|
||||
self._conflict_backoff_until: float = 0.0 # epoch time; skip polling until then
|
||||
|
||||
def register_command(
|
||||
self, command: str, handler: Callable[[], Awaitable[None]]
|
||||
@@ -575,12 +574,6 @@ class TelegramCommandHandler:
|
||||
async def _poll_loop(self) -> None:
|
||||
"""Main polling loop that fetches updates."""
|
||||
while self._running:
|
||||
# Skip this iteration while a conflict backoff is active
|
||||
now = asyncio.get_event_loop().time()
|
||||
if now < self._conflict_backoff_until:
|
||||
await asyncio.sleep(self._polling_interval)
|
||||
continue
|
||||
|
||||
try:
|
||||
updates = await self._get_updates()
|
||||
for update in updates:
|
||||
@@ -612,15 +605,13 @@ class TelegramCommandHandler:
|
||||
if resp.status != 200:
|
||||
error_text = await resp.text()
|
||||
if resp.status == 409:
|
||||
# Another bot instance is already polling — back off to reduce conflict.
|
||||
_conflict_backoff_secs = 30.0
|
||||
self._conflict_backoff_until = (
|
||||
asyncio.get_event_loop().time() + _conflict_backoff_secs
|
||||
)
|
||||
# Another bot instance is already polling — stop this poller entirely.
|
||||
# Retrying would keep conflicting with the other instance.
|
||||
self._running = False
|
||||
logger.warning(
|
||||
"Telegram conflict (409): another instance is polling. "
|
||||
"Backing off %.0fs. Ensure only one bot instance runs at a time.",
|
||||
_conflict_backoff_secs,
|
||||
"Telegram conflict (409): another instance is already polling. "
|
||||
"Disabling Telegram commands for this process. "
|
||||
"Ensure only one instance of The Ouroboros is running at a time.",
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
|
||||
Reference in New Issue
Block a user