unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 691 forks source link

websocket ping frame's not being sent #1122

Closed danieleden closed 8 years ago

danieleden commented 8 years ago

Hi guys, need some help with a websocket issue im having.

Im using django-websocket-redis lib with uwsgi in emperor mode to proxy websockets to back end uwsgi setup. The socket is created via call to /ws on nginx, this part works fine. Im able to load up a connection via nginx, im using a uswgi unix socket (tried TCP as well), ive setup the nginx conf exactly how its described in ws4redis docs (split uwsgi+websocket setup). My browser makes the connection into /ws?subscribe-broadcast, i can see the "--heartbeats--" being sent in and out of the websocket, then about 1:45s into the session it gets dropped with a "1006" close code. Im able to send a subscribe message and i can see all my test browsers receiving the message.

I have tried to set the proxy_read_timeout to no avail, ive tried the send_timeout too, keepalive_timeout, nothing is working for me.

Ive searched far and wide and everyone suggests that i set proxy_read_timeout but this does not do anything for me. I was wondering if there was an issue running a UDS as the read_timeout might be set via a TCP flag but i swapped over to TCP on localhost and same thing, 1.45second in the websocket ends.

Ive reverted back to ws (not wss) to sit on the wire and watch the session, what i have noticed is; …

  1. Client/Server exchange "--heartbeat--" (this i already knew from being in the frame on Chrome).
  2. Client sends a periodic "PONG" frame to the Server, this is never answered with a PING frame (seems out of order to me?)
  3. Server closes client connection with FIN/ACK after 1.45seconds
  4. Server never sends a single PING frame.

    I tired setting the websocket-ping-freq opt's in uwsg (set it to 5), it seemed to give me another 15 seconds or so of longevity but still closes off after that. Ive also sat on the wire with some test ws setups online to watch the transaction, all of those are sending PING's from server to client. I sat on the ws4redis demo site and watched the server PING and the client PONG, im assuming that setup is exactly how im running my setup.

Im using nginx 1.8 stable with latest version of uwsgi.

Would really appreciate some assistance.

xrmx commented 8 years ago

@danieleden please share your uwsgi configuration. Does uwsgi logs something interesting?

danieleden commented 8 years ago
[uwsgi]
pidfile = /run/uwsgi/djangowebsocket.pid
stats = /run/uwsgi/stats.sock
cap = setgid,setuid
chdir = /data/app
env = DJANGO_SETTINGS_MODULE=app.settings
module = app.wsgi_websocket:application
http-socket = /run/uwsgi/djangowebsocket.sock
#http-socket = 127.0.0.1:9090
http-websockets=true
#websocket-ping-freq = 1 
#websocket-pong-tolerance = 1
chmod-socket=777
plugins = python
processes = 5 
harakiri = 100 
max-requests = 5000
master = True
daemonize = /var/log/uwsgi/websocket.log
gevent=1000
workers= 5

Logs show nothing in regards to any errors or disconnects etc.

xrmx commented 8 years ago

@danieleden tried removing harakiri and max_requests options? also workers and processes are the same.

danieleden commented 8 years ago

@xrmx - you are the man Roberto ! it seems like harakiri was infact the issue here! Im now 100% working :) Many thanks for your prompt assistance, really appreciate it.

xrmx commented 8 years ago

@danieleden am not Roberto but you are welcome. Since it was a configuration error please next time use the mailing list and not github. Github is for bugs and not for support ;)