mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix race condition. let write die if we get EPIPE more than one time in
the loop
This commit is contained in:
parent
73431574a5
commit
c613b826c8
@ -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:
|
||||
|
||||
@ -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":
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user