mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Avoid race condition in dict iteration.
Its possible that when iterating Arbiter.WORKERS in manage_workers we get interupted to handle a SIGCHLD which will pop the child PID from the dict which results in a "dict changed size while iterating error. Reported on IRC. Simple fix is to just copy the dict into a list that we iterate.
This commit is contained in:
parent
e1e634a8aa
commit
6d69509bb6
@ -419,12 +419,10 @@ class Arbiter(object):
|
|||||||
if len(self.WORKERS.keys()) < self.num_workers:
|
if len(self.WORKERS.keys()) < self.num_workers:
|
||||||
self.spawn_workers()
|
self.spawn_workers()
|
||||||
|
|
||||||
num_to_kill = len(self.WORKERS) - self.num_workers
|
workers = self.WORKERS.items()
|
||||||
for i in range(num_to_kill, 0, -1):
|
workers.sort(key=lambda w: w.age)
|
||||||
pid, age = 0, sys.maxint
|
while len(workers) > self.num_workers:
|
||||||
for (wpid, worker) in self.WORKERS.iteritems():
|
(pid, _) = workers.pop(0)
|
||||||
if worker.age < age:
|
|
||||||
pid, age = wpid, worker.age
|
|
||||||
self.kill_worker(pid, signal.SIGQUIT)
|
self.kill_worker(pid, signal.SIGQUIT)
|
||||||
|
|
||||||
def spawn_worker(self):
|
def spawn_worker(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user