3

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.
4
  • post your consumer and routing code Commented Jan 10, 2019 at 16:53
  • I got it fixed with adding StopConsumer() thank you. Commented Jan 10, 2019 at 17:51
  • Where did you add StopConsumer() ?? I have the same issue. Commented Jul 26, 2020 at 5:48
  • stackoverflow.com/questions/53445286/… Please refer to this. You should be raising it on disconnect Commented Jul 26, 2020 at 23:07

1 Answer 1

1

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."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.