Django channels stops working after some time

I have a system that has two forms of communication, one through http connections for specific tasks and another through websockets for tasks that require real-time communication.

For the deployment I used nginx, daphne and redis, these are the configurations:

Service

[Unit]
Description=FBO
Requires=fbo.socket
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/api.fbo.org.py/backend
Environment="DJANGO_SETTINGS_MODULE=fbo-backend.settings"
ExecStart=/var/www/api.fbo.org.py/backend/.venv/bin/daphne \
        --bind 127.0.0.1 -p 8001 \
        fbo-backend.asgi:application

[Install]
WantedBy=multi-user.target

Nginx

server {
   server_name api.fbo.org.py;

   access_log /var/log/nginx/access.log custom_format;

   location /static/ {
        alias /var/www/api.fbo.org.py/backend/staticfiles/;
        expires 86400;
        log_not_found off;
   }

    location /media/ {
        root /var/www/api.fbo.org.py/backend;
        expires 86400;
        log_not_found off;
    }

    location / {
        proxy_pass http://localhost:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
    }

    location /ws/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }
}

Library versions

channels==4.0.0
channels-redis==4.2.0
daphne==4.1.2
Django==3.2.25

Reviewing the log when the system crashes I found that the following is repeated for different actions performed on the system:

WARNING  Application instance <Task pending name='Task-3802' coro=<ProtocolTypeRouter.__call__() running at /var/www/api.bancodeojos.org.py/backend/.venv/lib/python3.8/site-packages/channels/routing.py:62> wait_for=<Future pending cb=[shield.<locals>._outer_done_callback() at /usr/lib/python3.8/asyncio/tasks.py:902, <TaskWakeupMethWrapper object at  0x7f93a6c84c70>()]>> for connection <WebRequest at 0x7f93a6754b80 method=PUT uri=/turns/9141/ clientproto=HTTP/1.0> took too long to shut down and was killed.

I tried changing the versions of the libraries, increasing the response time and other options that I read from people who have the same problem but nothing worked, do you have any idea how to solve this?

Back to Top