channels_redis icon indicating copy to clipboard operation
channels_redis copied to clipboard

Application instance took too long to shut down and was killed. For websocket_disconnect() in AsyncConsumer

Open alamorre opened this issue 4 years ago • 2 comments

It seems that upon any websocket_disconnect call in a Consumer Class which inherits from AsyncConsumer we get the following error.

Application instance <Task pending coro=<SessionMiddlewareInstance.__call__() running at /Users/adamlamorre/Work/Adam/ChatEngine/api.chatengine.io/venv/lib/python3.6/site-packages/channels/sessions.py:183> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fcf742f7d08>()]>> for connection <WebSocketProtocol client=['127.0.0.1', 63557] path=b'/person_v3/'> took too long to shut down and was killed.

Here is an example consumer to recreate:

from channels.consumer import AsyncConsumer

class ExampleConsumer(AsyncConsumer):

    async def websocket_connect(self, event):
        await self.send({"type": "websocket.accept"})

    async def websocket_receive(self, event):
        if str(event['text']) == '"ping"':
            await self.send({
                "type": "websocket.send",
                "text": "pong"
            })

    async def websocket_disconnect(self, event):
       # Do anything
       pass

Here are my relevant dependencies and their versions:

asgiref==3.2.10
channels==2.4.0
channels-redis==3.1.0
daphne==2.5.0
Django==3.1.2
djangorestframework==3.11.2

They are older versions to avoid this issue per MrVhek's comment

alamorre avatar Aug 31 '21 01:08 alamorre

I have same issue :(

duyanh14 avatar Oct 18 '21 18:10 duyanh14

That older post has an answer to this here here. Basically, don't override websocket_disconnect, override disconnect

mssalnikov avatar Dec 16 '21 00:12 mssalnikov