A
A
Alexander2018-12-13 09:41:51
Django
Alexander, 2018-12-13 09:41:51

After closing the page websocket still works?

After the client connects to the sockets, a function is triggered on the server that is processed for about 1-2 seconds, then returns the result to the client via websockets. The problem is that if you reload the page ten times in a row, then the function will be processed ten times and then this data will fly into the milk, which generates an error:

2018-12-13 11:14:38,459 WARNING  Application instance <Task pending coro=<SessionMiddlewareInstance.__call__() running at /var/www/my_project/.venv/lib/python3.6/site-packages/channels/sessions.py:179> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.6/asyncio/futures.py:407, <TaskWakeupMethWrapper object at 0x7f6bc08826d8>()]>> for connection <WebSocketProtocol client=['my_ip', 63499] path=b'/ws/ticket/12/24/'> took too long to shut down and was killed.

And the next client will wait about half a minute for a response from the websocket.
How to be? is it possible to solve the problem at the nginx level? Django
2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-12-13
@sergey-gornostaev

First, running tasks and coroutines must be canceled in the disconnect method. Secondly, there is an unclosed bug in Daphne with the same symptoms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question