mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 19:21:29 +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):
|
||||
"""Parse the request from the unreader."""
|
||||
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
|
||||
mode = self.cfg.proxy_protocol
|
||||
@ -174,12 +174,10 @@ class AsyncRequest:
|
||||
|
||||
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."""
|
||||
data = await self.unreader.read()
|
||||
if not data:
|
||||
if stop:
|
||||
raise StopIteration()
|
||||
raise NoMoreData(bytes(buf))
|
||||
buf.extend(data)
|
||||
|
||||
|
||||
@ -186,9 +186,6 @@ class ASGIProtocol(asyncio.Protocol):
|
||||
peername,
|
||||
self.req_count
|
||||
)
|
||||
except StopIteration:
|
||||
# No more data, close connection
|
||||
break
|
||||
except NoMoreData:
|
||||
# Client disconnected
|
||||
break
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user