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
|
self._chunk_eof = False
|
||||||
|
|
||||||
def headers(self, headers, buf):
|
def headers(self, headers, buf):
|
||||||
""" take a string buff. It return
|
""" take a string as buffer and an header dict
|
||||||
new position or -1 if parsing isn't done.
|
(empty or not). It return new position or -1
|
||||||
headers dict is updated.
|
if parsing isn't done. headers dict is updated
|
||||||
|
with new headers.
|
||||||
"""
|
"""
|
||||||
if self._headers:
|
if self._headers:
|
||||||
return 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")
|
ld = len("\r\n\r\n")
|
||||||
i = buf.find("\r\n\r\n")
|
i = buf.find("\r\n\r\n")
|
||||||
if i != -1:
|
if i != -1:
|
||||||
|
|||||||
@ -81,7 +81,6 @@ class HTTPRequest(object):
|
|||||||
|
|
||||||
buf = buf[i:]
|
buf = buf[i:]
|
||||||
|
|
||||||
|
|
||||||
self.log.info("Got headers:\n%s" % headers)
|
self.log.info("Got headers:\n%s" % headers)
|
||||||
|
|
||||||
if headers.get('Except', '').lower() == "100-continue":
|
if headers.get('Except', '').lower() == "100-continue":
|
||||||
|
|||||||
@ -37,8 +37,6 @@ class HTTPResponse(object):
|
|||||||
|
|
||||||
write(self.sock, "%s\r\n" % "".join(resp_head))
|
write(self.sock, "%s\r\n" % "".join(resp_head))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for chunk in list(self.data):
|
for chunk in list(self.data):
|
||||||
write(self.sock, chunk)
|
write(self.sock, chunk)
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@ def read_partial(sock, length):
|
|||||||
def write(sock, data):
|
def write(sock, data):
|
||||||
buf = ""
|
buf = ""
|
||||||
buf += data
|
buf += data
|
||||||
|
i = 0
|
||||||
while buf:
|
while buf:
|
||||||
try:
|
try:
|
||||||
bytes = sock.send(buf)
|
bytes = sock.send(buf)
|
||||||
@ -60,8 +61,10 @@ def write(sock, data):
|
|||||||
if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
|
if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
|
||||||
break
|
break
|
||||||
elif e[0] in (errno.EPIPE,):
|
elif e[0] in (errno.EPIPE,):
|
||||||
|
if i == 0:
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
i += 1
|
||||||
|
|
||||||
def write_nonblock(sock, data):
|
def write_nonblock(sock, data):
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user