fix possible race condition when socket.error isn't raised but remote

connection was closed.
This commit is contained in:
benoitc 2010-03-08 16:57:32 +01:00
parent 4873b41b33
commit 5f5b67da96
2 changed files with 15 additions and 1 deletions

View File

@ -19,6 +19,9 @@ import tempfile
from gunicorn import util
class UnexpectedEOF(object):
""" exception raised when remote closed the connection """
class TeeInput(object):
CHUNK_SIZE = util.CHUNK_SIZE
@ -163,8 +166,17 @@ class TeeInput(object):
if self.parser.body_eof():
break
if not self._is_socket:
if self.parser.is_chunked:
data = buf2.getvalue()
if data.find("\r\n") >= 0:
continue
raise UnexpectedEOF("remote closed the connection")
data = self._sock.recv(length)
if not data:
self._is_socket = False
buf2.write(data)
self._finalize()

View File

@ -16,7 +16,7 @@ import traceback
from gunicorn import http
from gunicorn import util
from gunicorn.http.tee import UnexpectedEOF
class Worker(object):
@ -160,6 +160,8 @@ class Worker(object):
self.log.exception("Error processing request.")
else:
self.log.warn("Ignoring EPIPE")
except UnexpectedShutdown:
self.log.exception("remote closed the connection unexpectedly.")
except Exception, e:
self.log.exception("Error processing request.")
try: