From c613b826c8ff2510f5bb6548b52b53a349cb8d58 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Tue, 19 Jan 2010 20:08:01 +0100 Subject: [PATCH] fix race condition. let write die if we get EPIPE more than one time in the loop --- gunicorn/http/http_parser.py | 10 ++++------ gunicorn/http/request.py | 1 - gunicorn/http/response.py | 2 -- gunicorn/util.py | 7 +++++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gunicorn/http/http_parser.py b/gunicorn/http/http_parser.py index 3a68be71..464179cf 100644 --- a/gunicorn/http/http_parser.py +++ b/gunicorn/http/http_parser.py @@ -17,16 +17,14 @@ class HttpParser(object): self._chunk_eof = False def headers(self, headers, buf): - """ take a string buff. It return - new position or -1 if parsing isn't done. - headers dict is updated. + """ take a string as buffer and an header dict + (empty or not). It return new position or -1 + if parsing isn't done. headers dict is updated + with new headers. """ if self._headers: return self._headers - # wee could be smarter here - # by just reading the array, but converting - # is enough for now ld = len("\r\n\r\n") i = buf.find("\r\n\r\n") if i != -1: diff --git a/gunicorn/http/request.py b/gunicorn/http/request.py index 9b844c99..755f4c0d 100644 --- a/gunicorn/http/request.py +++ b/gunicorn/http/request.py @@ -81,7 +81,6 @@ class HTTPRequest(object): buf = buf[i:] - self.log.info("Got headers:\n%s" % headers) if headers.get('Except', '').lower() == "100-continue": diff --git a/gunicorn/http/response.py b/gunicorn/http/response.py index 9fd0f588..43c668b5 100644 --- a/gunicorn/http/response.py +++ b/gunicorn/http/response.py @@ -37,8 +37,6 @@ class HTTPResponse(object): write(self.sock, "%s\r\n" % "".join(resp_head)) - - for chunk in list(self.data): write(self.sock, chunk) diff --git a/gunicorn/util.py b/gunicorn/util.py index 013c01ca..cc79c5f5 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -49,6 +49,7 @@ def read_partial(sock, length): def write(sock, data): buf = "" buf += data + i = 0 while buf: try: bytes = sock.send(buf) @@ -60,9 +61,11 @@ def write(sock, data): if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN): break elif e[0] in (errno.EPIPE,): - continue + if i == 0: + continue raise - + i += 1 + def write_nonblock(sock, data): while True: try: