refactor(chat_manager.py): close connection in finally block to prevent memory leaks and improve code readability

This commit is contained in:
Gabriel Almeida 2023-04-25 23:17:45 -03:00
commit 5894f32ab0

View file

@ -166,11 +166,14 @@ class ChatManager:
await self.process_message(client_id, payload)
except Exception as e:
# Handle any exceptions that might occur
print(f"Error: {e}")
logger.exception(e)
# send a message to the client
await self.send_message(client_id, f"Error: {e}")
raise e
finally:
await self.active_connections[client_id].close(
code=1000, reason="Client disconnected"
)
self.disconnect(client_id)