Skip to content

Commit

Permalink
Fix issue when websocket is deleted when data is being sent.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Jan 2, 2024
1 parent a47f609 commit 8e2c99e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ async def send_bytes(self, event, data, sid=None):
message = self.encode_bytes(event, data)

if sid is None:
for ws in self.sockets.values():
sockets = list(self.sockets.values())
for ws in sockets:
await send_socket_catch_exception(ws.send_bytes, message)
elif sid in self.sockets:
await send_socket_catch_exception(self.sockets[sid].send_bytes, message)
Expand All @@ -593,7 +594,8 @@ async def send_json(self, event, data, sid=None):
message = {"type": event, "data": data}

if sid is None:
for ws in self.sockets.values():
sockets = list(self.sockets.values())
for ws in sockets:
await send_socket_catch_exception(ws.send_json, message)
elif sid in self.sockets:
await send_socket_catch_exception(self.sockets[sid].send_json, message)
Expand Down

0 comments on commit 8e2c99e

Please sign in to comment.