diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 5f918e2e74..849ec5134c 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -55,6 +55,7 @@ def __init__(self, cfg, sock, client, server): # set the socket to non blocking self.sock.setblocking(False) + self.active = False def init(self): self.sock.setblocking(True) @@ -149,7 +150,7 @@ def reuse_connection(self, conn, client): self._keep.remove(conn) except ValueError: # race condition - return + conn.active = True # submit the connection to a worker self.enqueue_req(conn) @@ -168,7 +169,8 @@ def murder_keepalived(self): if delta > 0: # add the connection back to the queue with self._lock: - self._keep.appendleft(conn) + if not conn.active: + self._keep.appendleft(conn) break else: self.nr_conns -= 1 @@ -259,6 +261,7 @@ def finish_request(self, fs): conn.set_timeout() with self._lock: self._keep.append(conn) + conn.active = False # add the socket to the event loop self.poller.register(conn.sock, selectors.EVENT_READ,