Websocket 200 error

53 views
Skip to first unread message

flora.xia...@gmail.com

unread,
Feb 18, 2019, 4:14:44 PM2/18/19
to Django users
Hi,

The real-time discussion function (supported by Daphne) on my website is not working (Other non-real-time functions are good). The console echos: "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during WebSocket handshake: Unexpected response code: 200". I've went through the blog posts and the documentation but couldn't find a solution. Can anyone help?

I am attaching information that I think is needed. If you need any other information please let me know.

The non-real-time part is supported by uwsgi (I know it can be supported by Daphne too. But since the real-time part is not working I decide to use uwsgi): 
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 --processes=6

daphne:
daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
python manage.py runworker -v2 &

nginx configuration:
upstream websocket { server 0.0.0.0:8000; } server { listen 80; server_name mysite.com; charset utf-8; client_max_body_size 20M; location /static { alias /path/to/mysite/static; } location / { include /etc/nginx/uwsgi_params;
uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass http://websocket; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
            proxy_redirect     off;
            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;
    }
}

One thing that I don't understand is that if I try to use Daphne to support both real-time and non-real-time communication by deleting the uwsgi block "location / {}" and renaming "location /ws {}" to "location / {}" the nginx service cannot be restarted. Does it suggest any bug?

first few lines in .js related to the discussion function:
$(function() {
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var chatsock = new ReconnectingWebSocket(ws_scheme + '://' + window.location.host + window.location.pathname);
......

flora.xia...@gmail.com

unread,
Feb 18, 2019, 4:15:30 PM2/18/19
to Django users
Thank you in advance!

flora.xia...@gmail.com

unread,
Feb 18, 2019, 9:19:52 PM2/18/19
to Django users
I am guessing maybe there is an issue with the redis-server? The log I received from Daphne:
2019-02-18 21:07:54,543 ERROR    Error trying to receive messages: Error running script (call to f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): @user_script:3: @user_script: 3: -MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

So I check redis log:
[1418] 18 Feb 16:09:27.071 * 1 changes in 900 seconds. Saving...
[1418] 18 Feb 16:09:27.072 * Background saving started by pid 2834
[2834] 18 Feb 16:09:27.073 # Failed opening .rdb for saving: Permission denied
[1418] 18 Feb 16:09:27.172 # Background saving error

I searched ways to solve the problem and set the permission of .rdb to 777. But still has this error in redis log.

I also find I cannot shutdown and restart redis. 

When I type redis-server in the command line, the log info:
[2892] 18 Feb 16:14:32.457 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[2892] 18 Feb 16:14:32.459 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984.
[2892] 18 Feb 16:14:32.459 # Creating Server TCP listening socket *:6379: bind: Address already in use

These are the redis processes running:
redis-ser  1418    redis    4u  IPv6  14515      0t0  TCP *:6379 (LISTEN)
redis-ser  1418    redis    5u  IPv4  14516      0t0  TCP *:6379 (LISTEN)
redis-ser  1418    redis    6u  IPv6 203617      0t0  TCP localhost:6379->localhost:34108 (ESTABLISHED)
redis-ser  1418    redis    7u  IPv6 202944      0t0  TCP localhost:6379->localhost:34104 (ESTABLISHED)

On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com wrote:

flora.xia...@gmail.com

unread,
Feb 19, 2019, 9:57:11 AM2/19/19
to Django users
The redis issue solved, by revising redis configuration: config set stop-writes-on-bgsave-error no
And the redis server can be restarted.
Reply all
Reply to author
Forward
0 new messages