AsyncHttpConsumer example from documentation hangs in send_response()
See original GitHub issueI’ve tried running example from https://channels.readthedocs.io/en/latest/topics/consumers.html#asynchttpconsumer but it does not work. It simply hangs up without sending any response body.
I’ve followed https://channels.readthedocs.io/en/latest/tutorial/index.html exactly step by step. Added channels
to INSTALLED_APPS, adjusted settings, added routing for http
requests only and 1 single AsyncHTTPConsumer
.
Doing verification step from https://channels.readthedocs.io/en/latest/tutorial/part_2.html “Let’s make sure that the channel layer can communicate with Redis…” also was performed successfully.
Example project: https://github.com/yuriiz/myproject/ Steps to reproduce:
git clone https://github.com/yuriiz/myproject.git
cd myproject
pip install -r requirements.txt
./manage.py migrate
./manage.py runserver
In another terminal:
curl localhost:8000/test
But requests hangs indefinitely. In runserver
output there is no error message or any other ouput.
After adding logging to https://github.com/yuriiz/myproject/blob/master/myproject/consumers.py and retrying only log message before send_response() is shown i.e. send_response() never returns.
Is there anything else which is not mentioned in documentation required to use AsyncHTTPConsumer?
Please also try and include, if you can:
- Your OS and runtime environment, and browser if applicable Tried on Ubuntu 19.04, Python3.7 and FreeBSD-11.3, Python3.6 with same result.
- A
pip freeze
output showing your package versions aioredis==1.2.0 asgiref==3.2.1 asn1crypto==0.24.0 async-timeout==3.0.1 attrs==19.1.0 autobahn==19.8.1 Automat==0.7.0 cffi==1.12.3 channels==2.2.0 channels-redis==2.4.0 constantly==15.1.0 cryptography==2.7 daphne==2.3.0 Django==2.2.4 hiredis==1.0.0 hyperlink==19.0.0 idna==2.8 incremental==17.5.0 msgpack==0.6.1 pkg-resources==0.0.0 pycparser==2.19 PyHamcrest==1.9.0 pytz==2019.2 six==1.12.0 sqlparse==0.3.0 Twisted==19.7.0 txaio==18.8.1 zope.interface==4.6.0 - What you expected to happen vs. what actually happened Server should return response. It hang up.
- How you’re running Channels (runserver? daphne/runworker? Nginx/Apache in front?) runserver
- Console logs and full tracebacks of any errors
$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
August 07, 2019 - 07:03:47
Django version 2.2.4, using settings 'myproject.settings'
Starting ASGI/Channels version 2.2.0 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
***before send_response()
(hangs)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Problem seems to be in
AsyncHTTPConsumer.http_request()
. Raising any exception insideAsyncHTTPConsumer.handle()
(including parameters misuse) will lead tofinally
block ofAsyncHTTPConsumer.http_request()
which will replace original exception withraise StopConsumer()
which will mask original exception and prevent user from seeing real cause of the problem neither through logs nor stderr which makes debugging such cases difficult.Hi @yuriiz. The docs were not automatically rebuild. I’ve rebuilt both versions so they now carry the correction. Sorry you ran into that.
Thank you for the sample project. I’ve opened an issue on Daphne for that. https://github.com/django/daphne/issues/276 — Daphne is meant to trigger an informative
ValueError
there, but is hanging instead so I’ll have a look at what’s going on there. (Now where’s my razor… 😃