From eb17b13b1df62fc12c5eebb72bc650c61979b5ae Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sat, 31 May 2014 13:28:16 -0700 Subject: [PATCH] Guard against race condition on threads keepalive Requests after the first on a keepalive connection remove themselves from the keepalive timeout queue. This presents a race condition where the main thread might try to access the first element of the queue after it has been removed. --- gunicorn/workers/gthread.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index f47eb7fc..789d869e 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -119,10 +119,11 @@ class ThreadWorker(base.Worker): def murder_keepalived(self): now = time.time() while True: - if not len(self._keep): + try: + delta = self._keep[0].timeout - now + except IndexError: break - delta = self._keep[0].timeout - now if delta > 0: break else: