🐛 fix(manager.py): catch and log RuntimeError when closing websocket connection to prevent unexpected ASGI message error
🔒 chore(manager.py): improve error handling when closing websocket connection to prevent unexpected ASGI message error
This commit is contained in:
parent
021e0526e8
commit
99be9830ad
1 changed files with 8 additions and 2 deletions
|
|
@ -104,8 +104,14 @@ class ChatManager:
|
||||||
|
|
||||||
async def close_connection(self, client_id: str, code: int, reason: str):
|
async def close_connection(self, client_id: str, code: int, reason: str):
|
||||||
if websocket := self.active_connections[client_id]:
|
if websocket := self.active_connections[client_id]:
|
||||||
await websocket.close(code=code, reason=reason)
|
try:
|
||||||
self.disconnect(client_id)
|
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(
|
async def process_message(
|
||||||
self, client_id: str, payload: Dict, langchain_object: Any
|
self, client_id: str, payload: Dict, langchain_object: Any
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue