Skip to content

Commit

Permalink
fix: treat ws as disconnected if send_text fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethnym committed Jul 29, 2024
1 parent 0179f03 commit 0f0edba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion websocket_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ async def connect(self, ws: WebSocket):
def disconnect(self, ws: WebSocket):
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):
await asyncio.gather(
*[conn.send_text(msg) for conn in self.__active_connections]
*[self.send_text(conn, msg) for conn in self.__active_connections]
)

0 comments on commit 0f0edba

Please sign in to comment.