From afa40eaa1888af4425bab5a82884336e751e5baa Mon Sep 17 00:00:00 2001 From: vectoralpha <35263669+vectoralpha@users.noreply.github.com> Date: Thu, 20 Jan 2022 20:58:13 -0500 Subject: [PATCH] Stop raising asyncio.CancelledError if the connection is already closed (#1152) * Update async_client.py * Update slack_sdk/socket_mode/async_client.py Co-authored-by: Kazuhiro Sera --- slack_sdk/socket_mode/async_client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/slack_sdk/socket_mode/async_client.py b/slack_sdk/socket_mode/async_client.py index 495ff88ed..478ee51d3 100644 --- a/slack_sdk/socket_mode/async_client.py +++ b/slack_sdk/socket_mode/async_client.py @@ -122,6 +122,11 @@ async def process_messages(self): while not self.closed: try: await self.process_message() + except asyncio.CancelledError: + # if self.closed is True, the connection is already closed + # In this case, we can ignore the exception here + if not self.closed: + raise except Exception as e: self.logger.exception( f"Failed to process a message: {e}, session: {session_id}"