django channels error message on websocket start (Sessions.py)

Viewed 1342

Whenever I start my django channels websocket. I get this:

2019-01-10 00:24:09,463 - WARNING - server - Application instance <Task pending coro=<SessionMiddlewareInstance.__call__() running at C:\Users\JAYK~1\Envs\jyst\lib\site-packages\channels\sessions.py:175> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000001B067F32E58>()]>> for connection <WebSocketProtocol client=['127.0.0.1', 57367] path=b'/jysts/m/KIDA_TG'> took too long to shut down and was killed.
1 Answers

My application was raising the same Warning as stated in the question. After some time it would kill the asgi application and the Websocket could no longer be connected to until i restarted the service manually.

For me it was adding raise StopConsumer() to the disconnect function:

def disconnect(self, close_code):
 # Leave room group
    async_to_sync(self.channel_layer.group_discard)(
        self.room_group_name,
        self.channel_name
    )
    raise StopConsumer()

As stated by the Channel Documentation: "you need to raise channels.exceptions.StopConsumer to halt the ASGI application cleanly and let the server clean it up. If you leave it running - by not raising this exception - the server will reach its application close timeout (which is 10 seconds by default in Daphne) and then kill your application and raise a warning."

Related