From 0a70d2d6680a41bea8a429fa7bacce6ce1688f1c Mon Sep 17 00:00:00 2001 From: Conatum Date: Fri, 6 Oct 2023 14:41:10 +0300 Subject: [PATCH] (timer): Add extra timeout to connect. --- src/modules/pomodoro/timer.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/pomodoro/timer.py b/src/modules/pomodoro/timer.py index fa5185d2..8198206b 100644 --- a/src/modules/pomodoro/timer.py +++ b/src/modules/pomodoro/timer.py @@ -481,14 +481,13 @@ class Timer: async with self.lguild.voice_lock: try: if self.guild.voice_client: - print("Disconnecting") await self.guild.voice_client.disconnect(force=True) - print("Disconnected") alert_file = focus_alert_path if stage.focused else break_alert_path try: - print("Connecting") - voice_client = await self.channel.connect(timeout=60, reconnect=False) - print("Connected") + voice_client = await asyncio.wait_for( + self.channel.connect(timeout=30, reconnect=False), + timeout=60 + ) except asyncio.TimeoutError: logger.warning(f"Timed out while connecting to voice channel in timer {self!r}") return @@ -515,13 +514,18 @@ class Timer: _, pending = await asyncio.wait([sleep_task, wait_task], return_when=asyncio.FIRST_COMPLETED) for task in pending: task.cancel() - - if self.guild and self.guild.voice_client: - await self.guild.voice_client.disconnect(force=True) + except asyncio.TimeoutError: + logger.warning( + f"Timed out while sending voice alert for timer {self!r}", + exc_info=True + ) except Exception: logger.exception( f"Exception occurred while playing voice alert for timer {self!r}" ) + finally: + if self.guild and self.guild.voice_client: + await self.guild.voice_client.disconnect(force=True) def stageline(self, stage: Stage): t = self.bot.translator.t