jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
894 stars 221 forks source link

Websocket never becomes ready. #221

Closed fizzy123 closed 7 years ago

fizzy123 commented 7 years ago

Hi. I'm trying to get your library set up with a basic application. For comparability, I didn't get your out of the box demo application set up, but I've got something similar in the code that I have and I'm running into a strange error.

I've got your demo javascript page setup and it keeps getting stuck in a loop of connecting, disconnecting, trying to reconnect, saying it has a connection, and then disconnecting again. In other words, the alerts cycle as such:

Websocket is connecting...
ws4redis.js:36 Connecting to ws://nobr.me/ws/foobar?subscribe-broadcast&publish-broadcast&echo ...
ws4redis.js:82 Connected!
ws4redis.js:96 Connection closed!
(index):35 Websocket was disconnected
ws4redis.js:55 Reconnecting...

I did some digging and I found what I suspect to be the problem. In line 113 of /ws4redis/wsgi_server.py, I pass an array consisting of my redis_fd and my websocket_fd to self.select. However, as it goes through the loop, only the redis_fd ever gets returned and nothing gets sent through the websocket fd.

My uwsgi ini file that I am using for wsgi_sockets.py is

[uwsgi]
chdir = /srv/nobelyoo/
umask = 002
master = true
no-orphans = true
uid = www-data
gid = adm
threads = 1
env = DJANGO_SETTINGS_MODULE=nobelyoo.settings
http-socket=/tmp/web.socket
module = nobelyoo.wsgi_websocket:application
processes = 1
http-websockets = true
gevent=1000

pidfile = /tmp/uwsgi.pid
daemonize=/var/log/uwsgi/%n.log

and my nginx file is

server {
    listen 80;
    server_name nobr.me www.nobr.me;

    access_log  /var/log/nginx/aa8000.access.log;
    error_log  /var/log/nginx/aa8000.error.log;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /var/www/;
    }

    location /media/ {
        root   /var/www/;
    }

                location /ws/ {
                                proxy_http_version 1.1;
                                proxy_set_header Upgrade "websocket";
                                proxy_set_header Connection "upgrade";
                                proxy_pass http://unix:/tmp/web.socket;
                }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/tmp/nobelyoo.sock;
    }
}

As you can see, I'm using Django with WebSockets for Redis behind NGiNX using uWSGI setup. I also hardcoded the $http_upgrade variable, since my nginx wasn't populating it properly for some reason and I was hoping that wouldn't be problematic.

Thanks for your help in advance and let me know if you have any more questions about my situation!

jrief commented 7 years ago

hmm, difficult to say. I assume it works with ./manage.py runserver?

Did you try the stand-alone mode with uWSGI without NGiNX?

fizzy123 commented 7 years ago

It hasn't worked without NGiNX in any form for me. Running without NGiNX caused the http_version and the various headers to not be set properly.

jrief commented 7 years ago

then you certainly messed up with the uWSGI settings, but that's off-topic.