unbit / uwsgi

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

uwsgi.websocket_send fails on messages >200-255kb #1602

Open kylemacfarlane opened 7 years ago

kylemacfarlane commented 7 years ago

Using uWSGI 2.0.15 and Python 3.5.1.

My WSGI script is a copy of: https://github.com/unbit/uwsgi/blob/2.0.15/tests/websockets_chat_async.py

I run it with:

uwsgi --socket /sockets/dev.websocket.sock --wsgi-file bin/websocket.wsgi --master --single-interpreter --chmod-socket=777 --async 10 --ugreen

When I try to send messages >200-255kb I get the following error:

uwsgi_response_write_body_do() TIMEOUT !!!
Traceback (most recent call last):
  File "/vagrant/src/app/wsgi_websocket.py", line 88, in application
    _handle_output(msg)
  File "/vagrant/src/app/wsgi_websocket.py", line 45, in _handle_output
    uwsgi.websocket_send(json.dumps(msg, separators=(',', ':')))
OSError: unable to send websocket message

1) This "timeout" happens immediately - not after 60s and is not affected by uwsgi_read_timeout.

2) The max size that can be sent varies each time uWSGI is started but it always seems to be between 200-255kb.

3) I've tried increasing options like ugreen-stacksize and websockets-max-size but they have no affect.

kylemacfarlane commented 7 years ago

This issue doesn't seem to exist if uwsgi is accessed directly by running with --http. This means it must be an nginx setting but I can't figure out what it could be. Adjusting uwsgi_buffers or even completely turning off uwsgi_buffering don't help.

funkybob commented 7 years ago

Does it make any difference if you enable post-buffering ?

kylemacfarlane commented 7 years ago

Websockets won't even connect when I use --post-buffering.

lucasdavid commented 6 years ago

Did you manage to fix this? I'm also having this issue.

kylemacfarlane commented 6 years ago

@lucasdavid I never managed to completely fix it but for me it's pretty rare in production. I think it's something related to #1716 combined with some nginx setting.

funkybob commented 6 years ago

Does it still happen in 2.0.16?

kylemacfarlane commented 6 years ago

@funkybob I haven't tested 2.0.16 but it was still happening in master from mid-January.

I did find that switching from ugreen to gevent reduced the errors but didn't completely fix it like I claimed in #1716.