From 08d5bfcbd0e6c9d30598fc248a5b7a0ac5ee5b2f Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 7 Nov 2020 12:06:10 +0100 Subject: [PATCH] Fix conv.wait_event not clearing timed out events Closes #1618. --- telethon/tl/custom/conversation.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/telethon/tl/custom/conversation.py b/telethon/tl/custom/conversation.py index 9bccb382..570707e9 100644 --- a/telethon/tl/custom/conversation.py +++ b/telethon/tl/custom/conversation.py @@ -336,7 +336,12 @@ class Conversation(ChatGetter): future = self._client.loop.create_future() self._custom[counter] = (event, future) - return await self._get_result(future, start_time, timeout, self._custom, counter) + try: + return await self._get_result(future, start_time, timeout, self._custom, counter) + except asyncio.TimeoutError: + # Need to remove it from the dict if it times out, else we may + # try and fail to set the result later (#1618). + del self._custom[counter] async def _check_custom(self, built): for key, (ev, fut) in list(self._custom.items()):