fix(telegram): widen NoneType reconnect guard to the conflict-retry path

The network-error reconnect ladder (#55992) captured a stable self._app
local across its awaits and failed fast when the adapter was torn down
mid-sleep. The 409-conflict retry path had the identical unguarded
self._app.updater.start_polling() deref — a concurrent disconnect()
during its RETRY_DELAY sleep would raise the same 'NoneType' object has
no attribute 'updater' and, on a non-final retry, land in limbo. Apply
the same stable-local + fail-fast pattern so the existing except block
reschedules or escalates to fatal.
This commit is contained in:
teknium1 2026-07-01 01:45:34 -07:00 committed by Teknium
parent fb8efbb4a8
commit 43edbae638

View file

@ -2165,8 +2165,17 @@ class TelegramAdapter(BasePlatformAdapter):
await asyncio.sleep(RETRY_DELAY)
await self._drain_polling_connections()
# Capture a stable local reference: self._app can be reassigned to
# None by a concurrent disconnect() while we're suspended across
# the awaits above (same race #55992 fixed on the network path).
# Re-reading self._app after that point would raise
# AttributeError deep inside start_polling instead of failing fast
# here, where the except below reschedules or escalates to fatal.
app = self._app
try:
await self._app.updater.start_polling(
if not app:
raise RuntimeError("Telegram application was torn down during conflict reconnect")
await app.updater.start_polling(
allowed_updates=Update.ALL_TYPES,
drop_pending_updates=False,
error_callback=self._polling_error_callback_ref,