From 99be9830adcc20460c389d54ca8f8e009c24dd54 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 9 Jul 2023 10:31:46 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(manager.py):=20catch=20and?= =?UTF-8?q?=20log=20RuntimeError=20when=20closing=20websocket=20connection?= =?UTF-8?q?=20to=20prevent=20unexpected=20ASGI=20message=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔒 chore(manager.py): improve error handling when closing websocket connection to prevent unexpected ASGI message error --- src/backend/langflow/chat/manager.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/chat/manager.py b/src/backend/langflow/chat/manager.py index 856ee226e..33de784b5 100644 --- a/src/backend/langflow/chat/manager.py +++ b/src/backend/langflow/chat/manager.py @@ -104,8 +104,14 @@ class ChatManager: async def close_connection(self, client_id: str, code: int, reason: str): if websocket := self.active_connections[client_id]: - await websocket.close(code=code, reason=reason) - self.disconnect(client_id) + try: + await websocket.close(code=code, reason=reason) + self.disconnect(client_id) + except RuntimeError as exc: + # This is to catch the following error: + # Unexpected ASGI message 'websocket.close', after sending 'websocket.close' + if "after sending" in str(exc): + logger.error(exc) async def process_message( self, client_id: str, payload: Dict, langchain_object: Any