question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncHttpConsumer example from documentation hangs in send_response()

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yuriizcommented, Aug 8, 2019

Problem seems to be in AsyncHTTPConsumer.http_request(). Raising any exception inside AsyncHTTPConsumer.handle() (including parameters misuse) will lead to finally block of AsyncHTTPConsumer.http_request() which will replace original exception with raise 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.

0reactions
carltongibsoncommented, Aug 7, 2019

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… 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-channels - Bountysource
When calling get_user() inside a consumer, sometimes the tests fail with a TimeoutError . The problem goes away when I remove this call...
Read more >
Consumers — Channels 4.0.0 documentation
Let's look at a basic example of a SyncConsumer : from channels.consumer import SyncConsumer class EchoConsumer(SyncConsumer): def websocket_connect(self, ...
Read more >
org.apache.spark.internal.Logging Scala Example
This page shows Scala examples of org.apache.spark.internal. ... Receiver private def receive() { var socket: Socket = null var userInput: String = null...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found