mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-07 21:21:30 +08:00
fix: resolve RuntimeError when StopIteration raised in ASGI coroutine
In Python 3.7+, PEP 479 converts StopIteration raised inside coroutines to RuntimeError. Changed _read_into() to raise NoMoreData instead, which is already properly handled by the protocol layer.
This commit is contained in:
parent
9508df658d
commit
d301d53758
@ -139,7 +139,7 @@ class AsyncRequest:
|
|||||||
async def _parse(self):
|
async def _parse(self):
|
||||||
"""Parse the request from the unreader."""
|
"""Parse the request from the unreader."""
|
||||||
buf = bytearray()
|
buf = bytearray()
|
||||||
await self._read_into(buf, stop=True)
|
await self._read_into(buf)
|
||||||
|
|
||||||
# Handle proxy protocol if enabled and this is the first request
|
# Handle proxy protocol if enabled and this is the first request
|
||||||
mode = self.cfg.proxy_protocol
|
mode = self.cfg.proxy_protocol
|
||||||
@ -174,12 +174,10 @@ class AsyncRequest:
|
|||||||
|
|
||||||
self._set_body_reader()
|
self._set_body_reader()
|
||||||
|
|
||||||
async def _read_into(self, buf, stop=False):
|
async def _read_into(self, buf):
|
||||||
"""Read data from unreader and append to bytearray buffer."""
|
"""Read data from unreader and append to bytearray buffer."""
|
||||||
data = await self.unreader.read()
|
data = await self.unreader.read()
|
||||||
if not data:
|
if not data:
|
||||||
if stop:
|
|
||||||
raise StopIteration()
|
|
||||||
raise NoMoreData(bytes(buf))
|
raise NoMoreData(bytes(buf))
|
||||||
buf.extend(data)
|
buf.extend(data)
|
||||||
|
|
||||||
|
|||||||
@ -186,9 +186,6 @@ class ASGIProtocol(asyncio.Protocol):
|
|||||||
peername,
|
peername,
|
||||||
self.req_count
|
self.req_count
|
||||||
)
|
)
|
||||||
except StopIteration:
|
|
||||||
# No more data, close connection
|
|
||||||
break
|
|
||||||
except NoMoreData:
|
except NoMoreData:
|
||||||
# Client disconnected
|
# Client disconnected
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user