Skip to content

Commit 3ab05b3

Browse files
committed
remove clients from dictionaries in stop()
1 parent 288cfc4 commit 3ab05b3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jupyter_rtc_core/websockets/clients.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,21 @@ def stop(self):
181181
Closes all Websocket connections with close code 1001 (server
182182
shutting down) and ignores any future calls to `add()`.
183183
"""
184+
# Remove all clients from both dictionaries
185+
client_ids = set(self.desynced.keys()) | set(self.synced.keys())
186+
clients: list[YjsClient] = []
187+
for client_id in client_ids:
188+
client = self.desynced.pop(client_id, None)
189+
if not client:
190+
client = self.synced.pop(client_id, None)
191+
if client:
192+
clients.append(client)
193+
194+
assert len(self.desynced) == 0
195+
assert len(self.synced) == 0
196+
184197
# Close all Websocket connections
185-
for client in self.get_all(synced_only=False):
198+
for client in clients:
186199
client.websocket.close(code=1001)
187200

188201
# Set `_stopped` to `True` to ignore future calls to `add()`

0 commit comments

Comments
 (0)