diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index 6c9c9b3..a9c8e0b 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -135,8 +135,18 @@ def getWebSocketHandler(central_command): logger.critical("Tried to send 'none' to Panopticon") return + toRemove = [] for client in wsHandlerClass.connections: - client.write_message(msg) + try: + client.write_message(msg) + except tornado.websocket.WebSocketClosedError as e: + logger.warning(f"Not properly closed websocket connection") + toRemove.append(client) # If we remove it here from the set we get an exception about changing set size during iteration + + for client in toRemove: + if client not in wsHandlerClass.connections: + continue + wsHandlerClass.connections.remove(client) return WebSocketHandler