channels icon indicating copy to clipboard operation
channels copied to clipboard

502, ProtocolTypeRouter took too long to shut down and was killed.

Open ghost opened this issue 2 years ago • 4 comments

i have gunicorn that accepts all http request, and daphne with asgi for websockets connections only. on my frontend i have reconnect script so i see that it start connection than from 5 to 10 times connection fails with error 502 and than connects. From log i see this.

 WARNING  Application instance <Task pending name='Task-30589' coro=<ProtocolTypeRouter.__call__() running at /usr/local/lib/python3.10/site-packages/channels/routing.py:71> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.10/asyncio/futures.py:384, Task.task_wakeup()]>> for connection <WebSocketProtocol client=['172.6.66.8', 0] path=b'/ws/profiles/'> took too long to shut down and was killed.
 WARNING  Application instance <Task pending name='Task-30555' coro=<ProtocolTypeRouter.__call__() running at /usr/local/lib/python3.10/site-packages/channels/routing.py:71> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.10/asyncio/futures.py:384, Task.task_wakeup()]>> for connection <WebSocketProtocol client=['172.6.66.8', 0] path=b'/ws/profiles/'> took too long to shut down and was killed.
 WARNING  Application instance <Task pending name='Task-30599' coro=<ProtocolTypeRouter.__call__() running at /usr/local/lib/python3.10/site-packages/channels/routing.py:71> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.10/asyncio/futures.py:384, Task.task_wakeup()]>> for connection <WebSocketProtocol client=['172.6.66.8', 0] path=b'/ws/profiles/'> took too long to shut down and was killed.

Django==4.0.6 daphne==3.0.2 channels==3.0.5 channels-redis==3.4.1 asgiref==3.5.2

ghost avatar Jul 22 '22 07:07 ghost

i change daphne server to https://www.uvicorn.org/, same thing, i have minimum 5-7 502 errors, and than mb it connects!

kojibhy avatar Jul 23 '22 19:07 kojibhy

@kojibhy Can you provide a minimal reproduce example please?

carltongibson avatar Jul 24 '22 10:07 carltongibson

I am not sure if my issue is the same, but it results in a similar error. In my case, I am running my Django Channels ASGI app using Daphne, and I have a couple API calls that call an external API. I found that when that external API errored out and I did not have a timeout set on the requests call, it would hang the Daphne server. While I did have a flaw in my code, I do not think that such a flaw should render the entire server unresponsive and not able to be restarted through systemctl. Note that when I switched to uvicorn, I no longer had an issue even with the misbehaving code. In my real application, I have of course fixed my external API calls to have an explicit timeout. Here is a simplified repro case based on my real application: https://github.com/jessamynsmith/daphne_hang/

Here is my exact error: 2023-02-14 05:01:42,735 WARNING Application instance <Task pending name='Task-6' coro=<ProtocolTypeRouter.call() running at /Users/jessamynsmith/Development/daphne_hang/venv/lib/python3.11/site-packages/channels/routing.py:62> wait_for=<Future pending cb=[_chain_future.._call_check_cancel() at /Users/jessamynsmith/.pyenv/versions/3.11.0/lib/python3.11/asyncio/futures.py:387, Task.task_wakeup()]>> for connection <WebRequest at 0x108603890 method=GET uri=/api/v1/hang/ clientproto=HTTP/1.1> took too long to shut down and was killed.

jessamynsmith avatar Feb 25 '23 15:02 jessamynsmith

Having the same issue.

pfcodes avatar Apr 17 '23 20:04 pfcodes