Navigation Menu

Skip to content

Commit

Permalink
Fix locking
Browse files Browse the repository at this point in the history
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 18, 2018
1 parent 78abbee commit f5bddaa
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions server.py
Expand Up @@ -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"]
Expand Down

0 comments on commit f5bddaa

Please sign in to comment.