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

Werkzeug 2.1.0 fails with WERKZEUG_SERVER_FD error #2368

Closed
sfuerte opened this issue Mar 31, 2022 · 6 comments
Closed

Werkzeug 2.1.0 fails with WERKZEUG_SERVER_FD error #2368

sfuerte opened this issue Mar 31, 2022 · 6 comments

Comments

@sfuerte
Copy link

sfuerte commented Mar 31, 2022

Upgrading to 2.1.0 leads to the following error:

"message": "Starting REST API"
"message": "'WERKZEUG_SERVER_FD'", 
"exc_info": "Traceback (most recent call last):
  ...
  self.app.run(host=self.host, port=self.port, debug=self.debug)
  File \"/usr/local/lib/python3.9/dist-packages/connexion/apps/flask_app.py\", line 104, in run
  self.app.run(self.host, port=self.port, debug=self.debug, **options)
  File \"/usr/local/lib/python3.9/dist-packages/flask/app.py\", line 920, in run
  run_simple(t.cast(str, host), port, self, **options)
  File \"/usr/local/lib/python3.9/dist-packages/werkzeug/serving.py\", line 1047, in run_simple
  fd = int(os.environ[\"WERKZEUG_SERVER_FD\"])
  File \"/usr/lib/python3.9/os.py\", line 679, in __getitem__
  raise KeyError(key) from None
  KeyError: 'WERKZEUG_SERVER_FD'"
"message": "SHUTDOWN"

Environment:

$ lsb_release -d
Description:	Debian GNU/Linux 11 (bullseye)

$ python3 --version
Python 3.9.2

# selected packages
$ pip3 list
Package               Version
--------------------- --------------
connexion             2.13.0
Flask                 2.1.0
Werkzeug              2.1.0

Workaround:

freezing Werkzeug @ 2.0.3 in requirements.txt (which we didn't have before as don't use it directly but it's rather a prerequisite of connexion and Flask)

Werkzeug==2.0.3
@davidism
Copy link
Member

davidism commented Mar 31, 2022

Looks like something you're using is messing with the dev server internals in a way that tricks it into thinking it's running in the reloader when it's not. Since it's not actually running in the reloader, certain things that it expects aren't set up correctly. You'll need to identify and report this to whatever is running the server this way.

@RobbeSneyders
Copy link
Contributor

@davidism could you point me to where connexion is messing with the dev server internals? I'm having a hard time reproducing the issue.

@davidism
Copy link
Member

davidism commented Apr 1, 2022

Yeah, I had a look and can't reproduce this either. If anyone is setting WERKZEUG_RUN_MAIN manually for some reason, that's what would mess with it. I updated the original comment.

@sfuerte
Copy link
Author

sfuerte commented Apr 1, 2022

@davidism, thanks for the hint. Apparently, it was set in systemd service file, removing that solved the issue.

# required to disable Flask debugging banner: "Serving Flask app (lazy loading) ..."
Environment="WERKZEUG_RUN_MAIN=true"

@davidism
Copy link
Member

davidism commented Apr 1, 2022

The fact that you're running this in systemd indicates a severe security issue with that application. Do not run the development server in production. It is not intended to be secure, stable, or efficient. Use a production server such as gunicorn, uwsgi, waitress, or mod_wsgi. The fact that you have to set an internal variable just to disable this message should be a strong indicator that you're doing something incorrect.

@sfuerte
Copy link
Author

sfuerte commented Apr 1, 2022

Thanks for the info. Will review what was done there :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants