From abac771c44f7cb889ff03e0dc0b08037202ea897 Mon Sep 17 00:00:00 2001 From: benoitc Date: Sun, 1 Jun 2014 20:36:48 +0200 Subject: [PATCH] fix race keepalived condition by popping/appending from left --- gunicorn/workers/gthread.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 5f660883..0f486642 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -120,11 +120,13 @@ class ThreadWorker(base.Worker): now = time.time() while True: try: - delta = self._keep[0].timeout - now + conn = self._keep.popleft() except IndexError: break + delta = conn.timeout - now if delta > 0: + self._keep.appendleft(conn) break else: # remove the connection from the queue