Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Socket handshake error when using gunicorn #78

Open
arliber opened this issue Jan 3, 2021 · 1 comment
Open

Socket handshake error when using gunicorn #78

arliber opened this issue Jan 3, 2021 · 1 comment

Comments

@arliber
Copy link

arliber commented Jan 3, 2021

I have a flask app that processes a web socket stream of audio from Twilio.

The app works fine without gunicorn but when I start it with gunicorn I get only the first message of the socket (connect) and an unsuccessful handshake. Here is how the app looks:

from flask import Flask
from flask_sockets import Sockets
from geventwebsocket.handler import WebSocketHandler
from gevent import pywsgi
...

app = Flask(__name__)
sockets = Sockets(app)
...
@sockets.route('/media')
def media(ws):
    ...
if __name__ == '__main__':
    server = pywsgi.WSGIServer(('', HTTP_SERVER_PORT), app, handler_class=WebSocketHandler)
    server.serve_forever()

When I start the app directly using python flaskapp.py it works ok.

When I start it using gunicorn by writing:

gunicorn -k flask_sockets.worker --bind 0.0.0.0:5055 --log-level=bug flaskapp:app

this is where the connection "hangs" and carries no further than the initial connection, apparently due to the handshake failing.

It's important to note that I haven't "gevent monkey patched" the code, but I'm not sure if it has anything to do with the problem.

Any idea will much be appreciated!

@enchant97
Copy link

Try launching gunicorn with this:
gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker --bind 0.0.0.0:5055 --log-level=bug flaskapp:app

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

No branches or pull requests

2 participants