Django-channels

Help me please! I have project django-channels. I user cache_layer redis. I deployed the application to digitalocean app platform. I’m doing load testing using and when the number of connections is more than 200 I get an error.
Stack
django 4.2.6
channels 4.0.0
channels-redis 4.2.0
daphne 4.0.0

After 200 connections from locust i have error
с```
alex-2/ERROR/locust.user.task: Handshake status 403 Forbidden -±± {‘date’: ‘Fri, 14 Jun 2024 08:26:44 GMT’, ‘transfer-encoding’: ‘chunked’, ‘connection’: ‘keep-alive’, ‘x-do-app-origin’: ‘8c16af01-84d7-49fd-901c-fcfa01070288’, ‘cache-control’: ‘private’, ‘x-do-orig-status’: ‘403’, ‘cf-cache-status’: ‘DYNAMIC’, ‘server’: ‘cloudflare’, ‘cf-ray’: ‘8938efed4b541c8c-AMS’} -±± None
Traceback (most recent call last):
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/locust/user/task.py”, line 340, in run
self.execute_next_task()
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/locust/user/task.py”, line 373, in execute_next_task
self.execute_task(self._task_queue.popleft())
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/locust/user/task.py”, line 487, in execute_task
task(self.user).run()
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/locust/user/task.py”, line 325, in run
self.on_start()
File “/Users/user/test_req/loadtesting/locustfile.py”, line 39, in on_start
self.ws = create_connection(ws_url, cookie=cookie_header)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/websocket/_core.py”, line 646, in create_connection
websock.connect(url, **options)
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/websocket/_core.py”, line 261, in connect
self.handshake_response = handshake(self.sock, url, *addrs, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/websocket/_handshake.py”, line 65, in handshake
status, resp = _get_resp_headers(sock)
^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/user/test_req/loadtesting/.venv/lib/python3.12/site-packages/websocket/_handshake.py”, line 150, in _get_resp_headers
raise WebSocketBadStatusException(
websocket._exceptions.WebSocketBadStatusException: Handshake status 403 Forbidden -±± {‘date’: ‘Fri, 14 Jun 2024 08:26:44 GMT’, ‘transfer-encoding’: ‘chunked’, ‘connection’: ‘keep-alive’, ‘x-do-app-origin’: ‘8c16af01-84d7-49fd-901c-fcfa01070288’, ‘cache-control’: ‘private’, ‘x-do-orig-status’: ‘403’, ‘cf-cache-status’: ‘DYNAMIC’, ‘server’: ‘cloudflare’, ‘cf-ray’: ‘8938efed4b541c8c-AMS’} -±± None


And error on sentry
Error occurred during connection: Error UNKNOWN while writing to socket. Connection lost.

Welcome @alexdzehil !

Are your websocket connections being made directly to daphne, or are they being proxied through nginx / apache / some other web server?

Are you seeing any error messages in the daphne log?

Is this limit you’re hitting exactly 200 connections and always 200 connections? Or is there any variability in that number?

If it’s exactly 200, then I’d check the DigitalOcean docs to see if they identify any limitations for the service you’re using. (You might also want to ask them this question, because this would sound to me like some type of configuration limit.)

I deployed both to before and simply deployed it on the server via ngnix and i see in error.logs in nginx

(111: Connection refused) while connecting to upstream, client: ***, server: ***, request: "GET /ws/game/ HTTP/1.1", upstream: "http://[::1]:8000/ws/game/", host: "***"

my nginx conf

upstream channels-backend {server localhost:8000;}

server {
        server_name ***;
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            alias /home/ubuntu/***/static/;
        }

        location /media/ {
            alias /home/ubuntu/***/media/;
        }

        location / {
                proxy_pass http://channels-backend;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_connect_timeout 60s;
                proxy_send_timeout 60s;
                proxy_read_timeout 60s;
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/***/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/***/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = ***) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name ****;
    return 404; # managed by Certbot


}