Skip to content
Permalink
Browse files

Fix locking

Calls to save() in purgeOld() and update() were in race condition.
Race condition was eliminated by extending the lock scope within purgeOld().
Calls to load() were in race condition with themselves.
While current use of load() (called only during construction of class ServerList()) does not manifest the bug, any future change introducing concurrent use of load() would.
Race condition potential was eliminated by extending the lock scope within load().
  • Loading branch information...
nOOb3167 authored and sfan5 committed Mar 17, 2018
1 parent 78abbee commit f5bddaaef57eb64039141070b61ded20cfbc67db
Showing with 9 additions and 9 deletions.
  1. +9 −9 server.py
@@ -349,19 +349,19 @@ def server_points(server):
def purgeOld(self):
with self.lock:
self.list = [server for server in self.list if time.time() <= server["update_time"] + app.config["PURGE_TIME"]]
self.save()
self.save()

def load(self):
try:
with open(os.path.join("static", "list.json"), "r") as fd:
data = json.load(fd)
except FileNotFoundError:
return
with self.lock:
try:
with open(os.path.join("static", "list.json"), "r") as fd:
data = json.load(fd)
except FileNotFoundError:
return

if not data:
return
if not data:
return

with self.lock:
self.list = data["list"]
self.maxServers = data["total_max"]["servers"]
self.maxClients = data["total_max"]["clients"]

0 comments on commit f5bddaa

Please sign in to comment.
You can’t perform that action at this time.