fix: treat ws as disconnected if send_text fails

This commit is contained in:
2024-07-29 13:27:40 +01:00
parent 0179f03b9a
commit 0f0edba926

View File

@@ -13,7 +13,13 @@ class WebSocketConnectionManager:
def disconnect(self, ws: WebSocket): def disconnect(self, ws: WebSocket):
self.__active_connections.remove(ws) self.__active_connections.remove(ws)
async def send_text(self, ws: WebSocket, msg: str):
try:
await ws.send_text(msg)
except:
self.__active_connections.remove(ws)
async def broadcast(self, msg: str): async def broadcast(self, msg: str):
await asyncio.gather( await asyncio.gather(
*[conn.send_text(msg) for conn in self.__active_connections] *[self.send_text(conn, msg) for conn in self.__active_connections]
) )