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().
This commit is contained in:
parent
78abbee771
commit
f5bddaaef5
20
server.py
20
server.py
@ -349,19 +349,19 @@ class ServerList:
|
||||
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
|
||||
|
||||
if not data:
|
||||
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
|
||||
|
||||
self.list = data["list"]
|
||||
self.maxServers = data["total_max"]["servers"]
|
||||
self.maxClients = data["total_max"]["clients"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user