miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.31k stars 888 forks source link

Weird behavior on AWS beanstalk deployment #1947

Closed RodrigoNeves95 closed 1 year ago

RodrigoNeves95 commented 1 year ago

I'm kinda running out of ideas and getting desperate at the same time ahah. I also don't know if this is the correct place but here it goes:

Trying to deploy a flask web-app using flask-socketio over a Docker AWS Beanstalk deployment. gevent is being used to serve the web app:

Note 1: The deployment used an AWS Application load balancer and entry point with a certificate and routes the traffic to a EC2 instance where a nginx server is running on port 80 to get the request and proxy them to the docker on port 5000 - This is the normal flow of the AWS Beanstalk stack

Note: no configuration at all was made to the nginx on the EC2 instnace

CMD ["gunicorn", "--bind", "0.0.0.0:5000","--workers","1", "--threads", "1", "application:application", "-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "--timeout", "180"]

First weird thing:

From the client if I do not force the protocol to to only use WebSocket I can't make the server go from polling to WebSocket. I get a 400 on the request. If I force to use Webscocket from the client I can make the ws protocol work.

Second weird thing:

If I actually remove gevent-websocket requirement and start the server with a gevent worker the server can make the request over polling, with no problem at all.

Third weird thing:

If I run the server with gevent-websocket support and force the client to run with ws only (to make sure I can actually use webscokets) I can run the web app normally, except for one tiny little thing that is driving me crazy: The first request to the server (after the login) is getting a 400 regardless of what I do. And this request is a normal HTTP GET method. All the requests after that first one, runs normally.

I'm also getting this weird things on the server output

<gevent._socket3.socket at 0x7fd3c5d2c1c0 object, fd=14, family=2, type=1, proto=6>: Invalid HTTP method: '3ff5ce1-583e6c977c0b74f445ff044d\r\n' 

I have no idea what this is and where it comes from

Happy to present all info needed