diff --git a/orchestrator/websocket/managers/memory_websocket_manager.py b/orchestrator/websocket/managers/memory_websocket_manager.py index 5c3539cf9..ed0b3b531 100644 --- a/orchestrator/websocket/managers/memory_websocket_manager.py +++ b/orchestrator/websocket/managers/memory_websocket_manager.py @@ -68,9 +68,9 @@ async def broadcast_data(self, channels: List[str], data: Dict) -> None: async def remove_ws(self, websocket: WebSocket, channel: str) -> None: if websocket.client_state != WebSocketState.DISCONNECTED: await self.disconnect(websocket) - if channel in self.connections_by_pid: + if channel in self.connections_by_pid and websocket in self.connections_by_pid[channel]: self.connections_by_pid[channel].remove(websocket) - if len(self.connections_by_pid[channel]): + if not len(self.connections_by_pid[channel]): del self.connections_by_pid[channel] self.log_amount_of_connections()