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:
|
||||
self.spawn_workers()
|
||||
|
||||
num_to_kill = len(self.WORKERS) - self.num_workers
|
||||
for i in range(num_to_kill, 0, -1):
|
||||
pid, age = 0, sys.maxint
|
||||
for (wpid, worker) in self.WORKERS.iteritems():
|
||||
if worker.age < age:
|
||||
pid, age = wpid, worker.age
|
||||
workers = self.WORKERS.items()
|
||||
workers.sort(key=lambda w: w.age)
|
||||
while len(workers) > self.num_workers:
|
||||
(pid, _) = workers.pop(0)
|
||||
self.kill_worker(pid, signal.SIGQUIT)
|
||||
|
||||
def spawn_worker(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user