Fix #57 - Errors when a socket is not properly closed

This commit is contained in:
Hugvey Central Command 2019-05-16 14:33:00 +02:00
parent 0d3a57794f
commit 4b67e0a6f2

View file

@ -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