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

Flask-SocketIO cross-contamination from other app #882

Closed
kf106 opened this issue Jan 22, 2019 · 9 comments
Closed

Flask-SocketIO cross-contamination from other app #882

kf106 opened this issue Jan 22, 2019 · 9 comments
Labels

Comments

@kf106
Copy link

kf106 commented Jan 22, 2019

I have two applications (bank-app.py and client-app.py), two separate venv installations, one for each. The bank-app.py uses socketio, the client-app.py is a plain flask app.

When I try to run the client-app on a different port, I get two serving messages, and it runs on the wrong port. This only started happening when I added the socketio stuff to the bank-app.py

The code is at https://github.com/kf106/blockchain-games

(venv-client) kf106@media-pc:/media/kf106/Elements/GIT/blockchain-games$ FLASK_RUN_PORT=5002 FLASK_APP=client-app.py flask run
 * Serving Flask-SocketIO app "client-app.py"
 * Forcing debug mode off
 * Serving Flask app "client-app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Any suggestions what is going on here?

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

So further investigation with a clean working directory: a basic flask app with a venv with no socketio works fine:

(venv) kf106@media-pc:~/test$ export FLASK_RUN_PORT=6667
(venv) kf106@media-pc:~/test$ FLASK_APP=client-app.py flask run
 * Serving Flask app "client-app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:6667/ (Press CTRL+C to quit)

but if I delete the venv folder and pycache, add Flask-SocketIO==3.1.2 to requirements.txt and then run through the same process again, SocketIO turns up, and the changed port (was 6667) is over-riden for the default 5000 port:

(venv) kf106@media-pc:~/test$ export FLASK_RUN_PORT=6667
(venv) kf106@media-pc:~/test$ FLASK_APP=client-app.py flask run
 * Serving Flask-SocketIO app "client-app.py"
 * Forcing debug mode off
 * Serving Flask app "client-app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

Furthermore, in the second case, if I stop the flask server, go into /home/kf106/test/venv-client/lib/python3.6 and manually delete the Flask_SocketIO-3.1.2.dist-info and flask-socketio folders, then run the flask run command again, it produces the first output.

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

I guess this is related to this: #713

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

So as a work-around, how can I get the FLASK_RUN_PORT working again?

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

FLASK_APP=client-app.py flask run --port 6667 apparently. So perhaps this issue should be called "Flask-socketIO doesn't pick up FLASK_RUN_PORT on flask run"

@miguelgrinberg
Copy link
Owner

@kf106 based on your description, my suggestion is that you do not install Flask-SocketIO in the venv for the project that doesn't use it.

At some point I had a fix in place for #713, but had to undo it as it affected the use of the reloader.

My currently thinking is that I'm going to stop supporting the use of flask run to start Flask-SocketIO apps. How are you starting your bank-app.py application? Do you use flask run or do you go with the "normal" way of running socketio.run(app)? I want to require the latter, so that I don't have to intercept flask run, which has proven very hard and also a moving target.

@kf106
Copy link
Author

kf106 commented Jan 22, 2019

I feel your pain with regards to flask run - I see why the flask maintainers switched to it, but it's broken a lot of stuff.

I use flask run because it's going to become the standard flasky way of doing things.

The problem I had was that the flask port variable wasn't being acted on (both apps will eventually need flask-socketIO, which is excellent, thank you very much!) and so they were both trying to grab port 5000. With --port it now works. I'm guessing getting flask-socketio to check for the environment variable and using it shouldn't be too hard a fix?

@miguelgrinberg
Copy link
Owner

@kf106 I can add the env vars, that's actually not that hard, but this is what I was referring to as a moving target. Each time Flask adds some option to the CLI that breaks my flask run copycat command. Somehow I missed the addition of the env vars in version 1. And the fact remains that my version of flask run is still broken when you install but don't use Flask-SocketIO.

@miguelgrinberg
Copy link
Owner

Starting with Flask-SocketIO 3.2.0 (just released), the flask run command can only be used with the threading mode. For all other async modes, the socketio.run(app) method should be used to start the server.

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

No branches or pull requests

2 participants