fix(gateway): clean up pending Telegram media groups on disconnect
Cancel any queued media-group flush tasks during Telegram adapter disconnect and clear the buffered events map so shutdown can't leave a pending album flush behind. Add a regression test covering disconnect before the debounce window expires.
This commit is contained in:
@@ -200,7 +200,15 @@ class TelegramAdapter(BasePlatformAdapter):
|
||||
return False
|
||||
|
||||
async def disconnect(self) -> None:
|
||||
"""Stop polling and disconnect."""
|
||||
"""Stop polling, cancel pending album flushes, and disconnect."""
|
||||
pending_media_group_tasks = list(self._media_group_tasks.values())
|
||||
for task in pending_media_group_tasks:
|
||||
task.cancel()
|
||||
if pending_media_group_tasks:
|
||||
await asyncio.gather(*pending_media_group_tasks, return_exceptions=True)
|
||||
self._media_group_tasks.clear()
|
||||
self._media_group_events.clear()
|
||||
|
||||
if self._app:
|
||||
try:
|
||||
await self._app.updater.stop()
|
||||
|
||||
Reference in New Issue
Block a user