Daphne freezes on some ws disconnects
See original GitHub issuepython 3.8
channels==2.3.1
channels-redis==2.4.1
daphne==2.4.0
Django==2.2.8
Entrypoint is daphne on alpine linux.
Consumer is quite simple:
class Consumer(AsyncWebsocketConsumer):
async def connect(self):
self.user = self.scope["user"]
self.name = self.scope["url_route"]["kwargs"]["name"]
# this line is changed by different subclasses
self.group_name = "%s%s" % ("chat-", self.name)
await self.accept()
# Join group
await self.channel_layer.group_add(self.group_name, self.channel_name)
if not True: # auth check
await self.send(text_data="not authorized")
await self.close()
# Receive message from group
async def m(self, event):
message = event["m"]
# Send message to WebSocket
await self.send(text_data=json.dumps(message))
This is the error that comes up after a random amount of disconnects:
2019-12-15 15:57:32,107 WARNING Application instance <Task pending name='Task-21465' coro=<SessionMiddlewareInstance.__call__() running at /usr/local/lib/python3.8/site-packages/channels/sessions.py:178> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.8/asyncio/futures.py:357, <TaskWakeupMethWrapper object at 0x7f7ebec32910>()]>> for connection <WebSocketProtocol client=['127.0.0.1', 41380] path=b'/api/ws/chat/ddd8ce11-50d0-456a-b8d8-15a068682d1e/'> took too long to shut down and was killed.
2019-12-15 15:57:33,108 ERROR Exception in callback AsyncioSelectorReactor.callLater.<locals>.run() at /usr/local/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287
handle: <TimerHandle when=1090864.949068441 AsyncioSelectorReactor.callLater.<locals>.run() at /usr/local/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py", line 290, in run
f(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/daphne/server.py", line 275, in application_checker
exception = application_instance.exception()
asyncio.exceptions.CancelledError
Subsequent requests, http and ws, aren’t served anymore. Timeout.
Any insight into this at all is greatly appreciated!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:27 (1 by maintainers)
Top Results From Across the Web
Django Channels: Get stuck after period of time - Stack Overflow
When I stop daphne server (with Ctrl+C), it takes about 5-10 minutes to completely go down. Sometime I have to run kill command....
Read more >Channels Websocket immedialty disconnecting with ssl-django
I tried to make run the tutorial from the channels docs on my production server, using ssl. After a few hours i managed...
Read more >Getting Started with Django Channels - Real Python
In this tutorial, we will use Django Channels to create a real-time application that updates a list of users as they log in...
Read more >python-websockets(1) - Arch manual pages
It is possible to restart the WebSocket server automatically but this isn't necessary for this tutorial. Try connecting and disconnecting the interactive client ......
Read more >subject:"Django channels"
Also, does anyone have any experience regarding the performance of using daphne, uvicorn or some other server?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Genarito I’m not able to update Django due to work considerations, but I did finally get things to work on Django 2.2.
This no longer throws the exception:
@adrzystek here’s the dependency stack that finally worked for me:
Thanks for all your help!
I can confirm @Genarito’s words, I had the same issue while on Python 3.8.2 but it was enough to upgrade
channels
(in my case from 2.3.0 to 2.4.0) andchannels-redis
(2.4.0 -> 3.1.0) packages.