From 09c1ff24921f156ca5db5e2e2d9a08e9f1e9021b Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 17 Apr 2020 17:31:37 +0100 Subject: [PATCH] Fix index error when cleaning out connections. --- stateserver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stateserver.py b/stateserver.py index aa329e1..02b635f 100755 --- a/stateserver.py +++ b/stateserver.py @@ -109,7 +109,8 @@ def getNextHourConnection() -> Optional[Connection]: def cleanOldConnections() -> None: global connections - for i in range(len(connections)): + #Go backwards round the loop so that pop's don't interfere with the index. + for i in range(len(connections)-1,-1,-1): if connections[i]["endTimestamp"] < datetime.datetime.now().timestamp(): connections.pop(i)