diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index 4455f920..7db290fd 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -228,9 +228,20 @@ class AbstractUser(ABC): sequential_updates=self.config["telegram.sequential_updates"], loop=self.loop, base_logger=base_logger, + update_error_callback=self._telethon_update_error_callback, ) self.client.add_event_handler(self._update_catch) + async def _telethon_update_error_callback(self, err: Exception) -> None: + if self.config["telegram.exit_on_update_error"]: + self.log.critical(f"Stopping due to update handling error {type(err).__name__}") + self.bridge.manual_stop(50) + else: + self.log.info("Recreating Telethon update loop in 60 seconds") + await asyncio.sleep(60) + self.log.debug("Now recreating Telethon update loop") + self.client._updates_handle = self.loop.create_task(self.client._update_loop()) + @abstractmethod async def update(self, update: TypeUpdate) -> bool: return False diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 0f0827b8..6f9badcf 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -230,6 +230,7 @@ class Config(BaseBridgeConfig): copy("telegram.catch_up") copy("telegram.sequential_updates") + copy("telegram.exit_on_update_error") copy("telegram.connection.timeout") copy("telegram.connection.retries") diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 5d868f11..ff7edf74 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -459,6 +459,7 @@ telegram: catch_up: true # Should incoming updates be handled sequentially to make sure order is preserved on Matrix? sequential_updates: true + exit_on_update_error: false # Telethon connection options. connection: diff --git a/requirements.txt b/requirements.txt index 2dd4b1a1..e1d8a480 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,9 +3,9 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.16.4,<0.17 +mautrix>=0.16.5,<0.17 #telethon>=1.24,<1.25 -tulir-telethon==1.25.0a14 +tulir-telethon==1.25.0a15 asyncpg>=0.20,<0.26 mako>=1,<2 setuptools