fix(gateway): guard NoneType in Telegram reconnect after network error (#55992) - #56028
fix(gateway): guard NoneType in Telegram reconnect after network error (#55992)#56028AlexFucuson9 wants to merge 1 commit into
Conversation
After sustained network errors, the reconnect handler sleeps with exponential backoff before calling start_polling(). During that sleep window the supervisor may tear down the adapter (disconnect() sets self._app = None). The existing stop() call was already guarded but start_polling() was not — accessing self._app.updater on a None app raised AttributeError and silently killed the reconnect loop. Add a None guard for both self._app and self._app.updater before the start_polling() call, matching the pattern used in stop(). Fixes NousResearch#55992
|
Superseded by PR #56200, which merged the root-cause fix for #55992. Your PR (submitted first — thank you) guarded the network-error reconnect path, but returning when self._app was gone left the adapter in the silent-limbo state that is the actual bug (no live polling, no scheduled retry, no fatal notification, so the gateway never requeues the platform). The merged fix captures a stable app ref and fails fast into the existing reschedule/fatal machinery, fixes the underlying TOCTOU double-disconnect in the gateway runner that nulls self._app in the first place, and widens the guard to the conflict-retry sibling path. Credited in the PR body. #56200 |
|
Superseded by #56224 (salvage of #56036), which fixes the same #55992 |
Problem
After sustained network errors, the Telegram adapter's
_handle_polling_network_errorreconnect handler sleeps with exponential backoff (5s–60s) before callingstart_polling(). During that sleep window the supervisor may tear down the adapter —disconnect()setsself._app = None(line 3028).The existing
stop()call at line 1777 was already guarded:But
start_polling()at line 1785 was not guarded:This crashes with
'NoneType' object has no attribute 'updater', silently killing the reconnect loop. The gateway process stays alive (state file says "running" + "connected") but never processes another Telegram message.Fix
Add a
Noneguard for bothself._appandself._app.updaterbefore thestart_polling()call, matching the pattern already used forstop(). If the app was destroyed during the reconnect delay, log a warning and abort cleanly.Reproduction
httpx.ConnectErrormultiple timesself._app = None)self._app.updater.start_polling()Testing
python3 -m py_compile plugins/platforms/telegram/adapter.py— syntax OKstop()guard at line 1777Fixes #55992