From 4b67e0a6f2e8f6d61f349913b92217bd1e018b3d Mon Sep 17 00:00:00 2001 From: Hugvey Central Command Date: Thu, 16 May 2019 14:33:00 +0200 Subject: [PATCH] Fix #57 - Errors when a socket is not properly closed --- hugvey/panopticon.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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