From 8b9cb09b6b40966f290a332e5f3806e13ec1c590 Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Tue, 16 Mar 2010 11:44:07 -0400 Subject: [PATCH] Be explicit about blocking status. Apparently the assumption that sockets don't inherit their blocking status from the server socket is invalid. Or python sets the flags to match. Either way, we need clients to use blocking sockets so we're now explicitly setting the blocking status. --- gunicorn/worker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gunicorn/worker.py b/gunicorn/worker.py index d0aee6e0..9cd393ba 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -97,12 +97,17 @@ class Worker(object): def accept(self): try: client, addr = self.socket.accept() + self.init_sock(client) self.handle(client, addr) self.nr += 1 except socket.error, e: if e[0] not in (errno.EAGAIN, errno.ECONNABORTED): raise + def init_sock(self, sock): + sock.setblocking(1) + util.close_on_exec(sock) + def run(self): self.init_process() self.nr = 0 @@ -145,7 +150,6 @@ class Worker(object): raise def handle(self, client, addr): - util.close_on_exec(client) try: req = http.Request(client, addr, self.address, self.conf)