mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-31 16:07:44 +03:00 
			
		
		
		
	Re-raise unhandled errors that occur during update handling
This should help the situation in #3870.
This commit is contained in:
		
							parent
							
								
									a83fe46baf
								
							
						
					
					
						commit
						49bdb762c9
					
				|  | @ -386,6 +386,7 @@ class TelegramBaseClient(abc.ABC): | ||||||
|         self._borrowed_senders = {} |         self._borrowed_senders = {} | ||||||
|         self._borrow_sender_lock = asyncio.Lock() |         self._borrow_sender_lock = asyncio.Lock() | ||||||
| 
 | 
 | ||||||
|  |         self._updates_error = None | ||||||
|         self._updates_handle = None |         self._updates_handle = None | ||||||
|         self._keepalive_handle = None |         self._keepalive_handle = None | ||||||
|         self._last_request = time.time() |         self._last_request = time.time() | ||||||
|  |  | ||||||
|  | @ -28,7 +28,10 @@ class UpdateMethods: | ||||||
|         try: |         try: | ||||||
|             # Make a high-level request to notify that we want updates |             # Make a high-level request to notify that we want updates | ||||||
|             await self(functions.updates.GetStateRequest()) |             await self(functions.updates.GetStateRequest()) | ||||||
|             return await self.disconnected |             result = await self.disconnected | ||||||
|  |             if self._updates_error is not None: | ||||||
|  |                 raise self._updates_error | ||||||
|  |             return result | ||||||
|         except KeyboardInterrupt: |         except KeyboardInterrupt: | ||||||
|             pass |             pass | ||||||
|         finally: |         finally: | ||||||
|  | @ -51,6 +54,8 @@ class UpdateMethods: | ||||||
| 
 | 
 | ||||||
|         It also notifies Telegram that we want to receive updates |         It also notifies Telegram that we want to receive updates | ||||||
|         as described in https://core.telegram.org/api/updates. |         as described in https://core.telegram.org/api/updates. | ||||||
|  |         If an unexpected error occurs during update handling, | ||||||
|  |         the client will disconnect and said error will be raised. | ||||||
| 
 | 
 | ||||||
|         Manual disconnections can be made by calling `disconnect() |         Manual disconnections can be made by calling `disconnect() | ||||||
|         <telethon.client.telegrambaseclient.TelegramBaseClient.disconnect>` |         <telethon.client.telegrambaseclient.TelegramBaseClient.disconnect>` | ||||||
|  | @ -246,6 +251,7 @@ class UpdateMethods: | ||||||
|     # region Private methods |     # region Private methods | ||||||
| 
 | 
 | ||||||
|     async def _update_loop(self: 'TelegramClient'): |     async def _update_loop(self: 'TelegramClient'): | ||||||
|  |         self._updates_error = None | ||||||
|         try: |         try: | ||||||
|             if self._catch_up: |             if self._catch_up: | ||||||
|                 # User wants to catch up as soon as the client is up and running, |                 # User wants to catch up as soon as the client is up and running, | ||||||
|  | @ -360,8 +366,10 @@ class UpdateMethods: | ||||||
|                 updates_to_dispatch.extend(self._preprocess_updates(processed, users, chats)) |                 updates_to_dispatch.extend(self._preprocess_updates(processed, users, chats)) | ||||||
|         except asyncio.CancelledError: |         except asyncio.CancelledError: | ||||||
|             pass |             pass | ||||||
|         except Exception: |         except Exception as e: | ||||||
|             self._log[__name__].exception('Fatal error handling updates (this is a bug in Telethon, please report it)') |             self._log[__name__].exception('Fatal error handling updates (this is a bug in Telethon, please report it)') | ||||||
|  |             self._updates_error = e | ||||||
|  |             await self.disconnect() | ||||||
| 
 | 
 | ||||||
|     def _preprocess_updates(self, updates, users, chats): |     def _preprocess_updates(self, updates, users, chats): | ||||||
|         self._mb_entity_cache.extend(users, chats) |         self._mb_entity_cache.extend(users, chats) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user