# Django-channels

**URL:** <https://forum.djangoproject.com/t/django-channels/32090>\
**Category:** Async/Channels\
**Created:** [June 14, 2024, 8:47am UTC](https://forum.djangoproject.com/t/django-channels/32090 "2024-06-14T08:47:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexdzehil](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alexdzehil/32/21954_2.png) [@alexdzehil](https://forum.djangoproject.com/u/alexdzehil)\
**Post date:** [June 14, 2024, 8:47am UTC](https://forum.djangoproject.com/t/django-channels/32090/1 "2024-06-14T08:47:30Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 14, 2024, 11:20am UTC](https://forum.djangoproject.com/t/django-channels/32090/2 "2024-06-14T11:20:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexdzehil](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alexdzehil/32/21954_2.png) [@alexdzehil](https://forum.djangoproject.com/u/alexdzehil)\
**Post date:** [June 14, 2024, 12:44pm UTC](https://forum.djangoproject.com/t/django-channels/32090/3 "2024-06-14T12:44:21Z")

</div>

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

```auto
(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

```auto
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

}

```
