Connection won't be closed when exception occurred in AsyncHttpConsumer::handle() and handle() have sent nothing using send() or send_body(). So client will be hanged there until timeout, with nothing received. In server-side, there is no exception traceback/information logged.
We can reproduce this case using following codes:
class DemoHttpConsumer(AsyncHttpConsumer):
async def handle(self, body):
raise ValueError()
I have read codes, it's because the exception occurred in handle() is ignore in
|
async def http_request(self, message): |
|
""" |
|
Async entrypoint - concatenates body fragments and hands off control |
|
to ``self.handle`` when the body has been completely received. |
|
""" |
|
if "body" in message: |
|
self.body.append(message["body"]) |
|
if not message.get("more_body"): |
|
try: |
|
await self.handle(b"".join(self.body)) |
|
finally: |
|
await self.disconnect() |
|
raise StopConsumer() |
In
finally statements, exception was ignored by raise StopConsumer(). So all coroutines will be waiting continues.
If send() something in AsyncHttpConsumer::handle(). Daphne will send {"type": "http.disconnect"} message in here:
https://github.com/django/daphne/blob/333f4644d1a5a167c85eca967a52e4e10a7db0bd/daphne/http_protocol.py#L257-L258
if not message.get("more_body", False):
self.finish()
logger.debug("HTTP response complete for %s", self.client_addr)
which make all coroutines exit.
Now I am selecting a web-socket framework used in my company's project.
Because I am a novice in python asynchronies programming and channels, I'm sorry can't submit a patch to fix it. So can you fix this problem soon?
Connection won't be closed when exception occurred in AsyncHttpConsumer::handle() and handle() have sent nothing using send() or send_body(). So client will be hanged there until timeout, with nothing received. In server-side, there is no exception traceback/information logged.
We can reproduce this case using following codes:
I have read codes, it's because the exception occurred in handle() is ignore in
channels/channels/generic/http.py
Lines 73 to 85 in f786fed
In
finallystatements, exception was ignored by raise StopConsumer(). So all coroutines will be waiting continues.If send() something in
AsyncHttpConsumer::handle(). Daphne will send{"type": "http.disconnect"}message in here:https://github.com/django/daphne/blob/333f4644d1a5a167c85eca967a52e4e10a7db0bd/daphne/http_protocol.py#L257-L258
which make all coroutines exit.
Now I am selecting a web-socket framework used in my company's project.
Because I am a novice in python asynchronies programming and channels, I'm sorry can't submit a patch to fix it. So can you fix this problem soon?