Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange empty string messages (not PING/PONGS) coming from .receive() #39

Open
fobdy opened this issue Oct 14, 2015 · 2 comments
Open

Comments

@fobdy
Copy link

fobdy commented Oct 14, 2015

i have the following configuration on mac:

Flask (0.10.1)
Flask-uWSGI-WebSocket (0.4.4)
gevent (1.0.2)
greenlet (0.4.9)
uWSGI (2.0.11.2)

my app code is:

from flask import Flask
from flask.ext.uwsgi_websocket import GeventWebSocket

app = Flask(__name__)
websocket = GeventWebSocket(app)

@websocket.route('/echo')
def echo(ws):
    while True:
        msg = ws.recv()
        if msg is None:
            return
        print type(msg)
        print 'MESSAGE RECEIVED!!! ', msg
        ws.send(msg)

The ws.recv() call periodically receives some empty string '' messages from nowhere. Client doesn't send them.

When i've plugged off the flask and flask-uwsgi-websocket the following code worked fine:

import uwsgi


def app(env, start_response):
    # complete the handshake
    uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'],
                              env.get('HTTP_ORIGIN', ''))
    while True:
        msg = uwsgi.websocket_recv()
        uwsgi.websocket_send(msg)

My uWSGI config is:

[uwsgi]
http-socket = 127.0.0.1:9090
wsgi-file = app.py
callable = app
gevent = 100
processes = 4
@adamjaso
Copy link

+1

@ibrewster
Copy link

What appears to be happening here is that either the WebSocketMiddleware or perhaps the underlying uwsgi web socket implementation periodically pushes an empty string onto the receive queue, rather than using the "timeout" function of the queue.

If I had to guess, I'd say that this is a rather kludgy attempt to replicate the "timeout" functionality without raising the "Empty" exception that the timeout would raise. So an empty string is functionally equivalent to an "Empty" exception.

I could be missing something though - this is just my conclusion based on observed behavior and a light perusing of the code (where I never did find the actual code pushing the empty string). Would be nice if it was documented though, along with the fact that a return value of None means "connection closed"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants