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
@ -352,6 +352,7 @@ class ServerList:
|
|||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
with self.lock:
|
||||||
try:
|
try:
|
||||||
with open(os.path.join("static", "list.json"), "r") as fd:
|
with open(os.path.join("static", "list.json"), "r") as fd:
|
||||||
data = json.load(fd)
|
data = json.load(fd)
|
||||||
@ -361,7 +362,6 @@ class ServerList:
|
|||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
|
||||||
with self.lock:
|
|
||||||
self.list = data["list"]
|
self.list = data["list"]
|
||||||
self.maxServers = data["total_max"]["servers"]
|
self.maxServers = data["total_max"]["servers"]
|
||||||
self.maxClients = data["total_max"]["clients"]
|
self.maxClients = data["total_max"]["clients"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user