gdbgui icon indicating copy to clipboard operation
gdbgui copied to clipboard

Fails to start with `KeyError: WERKZEUG_SERVER_FD`

Open hunger opened this issue 4 years ago • 31 comments

Describe the bug

gdbgui does not start. It fails with KeyError: WERKZEUG_SERVER_FD.

To Reproduce

  1. pipx install gdbgui
  2. gdbgui

I get this output:

1➜ gdbgui
Opening gdbgui with default browser at http://127.0.0.1:5000
View gdbgui dashboard at http://127.0.0.1:5000/dashboard
exit gdbgui by pressing CTRL+C
Traceback (most recent call last):
  File "/home/dev/.local/bin/gdbgui", line 8, in <module>
    sys.exit(main())
  File "/home/dev/.local/pipx/venvs/gdbgui/lib/python3.10/site-packages/gdbgui/cli.py", line 249, in main
    run_server(
  File "/home/dev/.local/pipx/venvs/gdbgui/lib/python3.10/site-packages/gdbgui/server/server.py", line 95, in run_server
    socketio.run(
  File "/home/dev/.local/pipx/venvs/gdbgui/lib/python3.10/site-packages/flask_socketio/__init__.py", line 596, in run
    app.run(host=host, port=port, threaded=True,
  File "/home/dev/.local/pipx/venvs/gdbgui/lib/python3.10/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/home/dev/.local/pipx/venvs/gdbgui/lib/python3.10/site-packages/werkzeug/serving.py", line 1047, in run_simple
    fd = int(os.environ["WERKZEUG_SERVER_FD"])
  File "/usr/lib/python3.10/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'WERKZEUG_SERVER_FD'

The firefox browser pops up before this output shows up but only shows an empty page.

Expected behavior

Gbdgui starts up and does something.

Please complete the following information:

  • OS: Linux
  • gdbgui version (gdbgui -v): 0.15.0.1
  • gdb version (gdb -v): GNU gdb (GDB) 11.2
  • browser [e.g. chrome, safari]: It does not get to a point where that should matter:-)
  • python packages (pip freeze):
appdirs==1.4.4
argcomplete==2.0.0
click==8.1.0
greenlet==1.1.2
lit==13.0.1.dev0
meson==0.62.0
more-itertools==8.10.0
msgpack==1.0.3
ordered-set==4.0.2
packaging==21.3
pipx==1.0.0
pynvim==0.4.3
pyparsing==3.0.7
six==1.16.0
TBB==0.2
userpath==1.8.0

Additional context I tried running this inside an systemd-nspawn container, which does cause trouble sometimes. But this does not look like the typical container issue.

hunger avatar Mar 30 '22 10:03 hunger

Try an older version of python library "werkzeug". Version 2.1.0 was faulty for me. Version 2.0.0 does work.

pip install werkzeug==2.0.0

saeugetier avatar Mar 30 '22 20:03 saeugetier

Same problem. Werkzeug==2.0.0

zenbooster avatar Mar 30 '22 21:03 zenbooster

Can this be fixed upstream by pinning the expected werkzeug version somehow? This is a pretty bad first-use impression!

hunger avatar Mar 31 '22 08:03 hunger

I think allways the latest version of Werkzeug is used. Werkzeug 2.1.0 is recently released: https://pypi.org/project/Werkzeug/#history Maybe a patch is necessary to fix that problem.

saeugetier avatar Mar 31 '22 14:03 saeugetier

I also met this issue, solved by reinstallation of werkzeug 2.0.0

BIAOXYZ avatar Apr 01 '22 05:04 BIAOXYZ

https://github.com/cs01/gdbgui/blob/799d34051419653cfda7d068806f853007d46fac/gdbgui/server/server.py#L93

This line is why it's failing. You're tricking Werkzeug into thinking it's running in the reloader, when it's not. This breaks the environment it expects to find when starting the server. Remove this line.

It seems this might have been done to enable debug=True while disabling the reloader? If that's the case, then the correct way to do that is to do app.run(debug=True, use_reloader=False).

davidism avatar Apr 01 '22 15:04 davidism

https://github.com/cs01/gdbgui/blob/799d34051419653cfda7d068806f853007d46fac/gdbgui/server/server.py#L93

This line is why it's failing. You're tricking Werkzeug into thinking it's running in the reloader, when it's not. This breaks the environment it expects to find when starting the server. Remove this line.

It seems this might have been done to enable debug=True while disabling the reloader? If that's the case, then the correct way to do that is to do app.run(debug=True, use_reloader=False).

While I agree with you, expliciltly setting os.environ['WERKZEUG_RUN_MAIN'] = 'true' is a widely used trick to hide the console prints:

 * Serving Flask app '' (lazy loading)
 * Environment: development
 * Debug mode: off

Do you have an idea how to hide these prints in werkzeug 2.1.0? Because this will probably prevent many people from upgrading from werkzeug 2.0.0

mattans avatar Apr 03 '22 13:04 mattans

You don't. That output is there for a reason, we want to very strongly make people aware that they are running a development server, and that it is not meant for production. The fact that setting an internal setup variable happened to suppress it was unintentional and never guaranteed to work.

"Production" means "not developing the application itself", even if it's a local application. The development server is not particularly secure, stable, or efficient. One way is to use a production server, such as waitress, which you can also import and run from Python code.

If you're really, really sure it's ok to run the development server and also don't want the output, then you can use make_server to create a server and call s.serve_forever() instead (possibly in a thread). This allows you to manually set up the server without all the other stuff that run_simple does. Again, be very very sure that running the development server is what you want for your users.

davidism avatar Apr 03 '22 13:04 davidism

Thanks for the answer.

mattans avatar Apr 03 '22 13:04 mattans

Installing werkzeug 2.0 hasn't actually solved the issue for me.

scotter1995 avatar Apr 03 '22 20:04 scotter1995

I get the same error as the OP, and installing werkzeug 2.0 does not solve the issue for me. Not sure if this is relevant: I'm running everything from within anaconda, on Xubuntu 20.04.

gdbgui with no customization did work for me about five days ago, but since that time I've reinstalled the OS and anaconda, pipx, and gdbgui, which seems consistent with something having changed in the last few days.

otinkyad avatar Apr 04 '22 03:04 otinkyad

Downgrading to 2.0.0 worked for me, on a newly installed Debian 11 system.

ElectricLab avatar Apr 04 '22 23:04 ElectricLab

I get the same error as the OP, and installing werkzeug 2.0 does not solve the issue for me. Not sure if this is relevant: I'm running everything from within anaconda, on Xubuntu 20.04.

gdbgui with no customization did work for me about five days ago, but since that time I've reinstalled the OS and anaconda, pipx, and gdbgui, which seems consistent with something having changed in the last few days.

Me too

sunyiynus avatar Apr 19 '22 12:04 sunyiynus

I reinstall werkzeug 2.0.0. It does fix this issue for me. My env: ubuntu 20.4 LTS

sunyiynus avatar Apr 19 '22 12:04 sunyiynus

Installing werkzeug 2.0 hasn't actually solved the issue for me.

You still having problems dude?

rempas avatar Apr 21 '22 15:04 rempas

Not sure about @scotter1995, but werkzeug 2.0.0 has still not solved the issue for me. I've tried a number of times.

But I am using in what may be a somewhat unusual environment (from Anaconda3, on Xubuntu 20.04 LTS). So I'm currently setting up Ubuntu 20.4 LTS in a VM and will install on that directly, andd without Anaconda. Will report back...

UPDATE: Nope, not working for me. Installed gdbgui in Ubuntu 20.04 LTS VM (no Anaconda mediation). Reverted werkzeug to 2.0.0. Still the same error: verbatim with the error listing from OP.

Moving on to a different GUI debugger...

otinkyad avatar Apr 21 '22 16:04 otinkyad

FURTHER UPDATE:

Decided to try one last thing. Following the suggestion made by @davidism I commented out line 93 in server.py.

Now it works for me.

[AND, LAST BUT NOT LEAST]: gdbgui is terrific! Many thanks and kudos to dev!

otinkyad avatar Apr 22 '22 17:04 otinkyad

Hi everyone, sorry for all the hassle with this issue. Looks like something needs to be adjusted in gdbgui's dependencies. I'll try to get to this but unfortunately have been extremely busy and unable to carve out time. You may have luck with a prebuilt binary or a pex from the releases page.

cs01 avatar Apr 22 '22 22:04 cs01

Hi everyone, I had the same issue with the werkzeug. I installed the gdbgui by following the instructions (Method 1) from here: https://www.gdbgui.com/installation/ and I was not able to start the tool due to the werkzeug, even with werkzeug==2.0.0. Afterwards I uninstalled the tool and installed it again but this time I used the second method and it worked for me.

MykolaMoshak avatar Apr 27 '22 08:04 MykolaMoshak

You don't

Challenge accepted.

import flask.cli
flask.cli.show_server_banner = lambda *args: None

No more annoying console text. Enjoy!

Update with hilarious comment @davidism posted and deleted for some reason:

I didn't say you can't, I said you don't. Don't do that. You're doing yourself and your users a disservice by hiding the security related message saying not to use the development server outside development.

  1. Trying to dictate your use of open source software.
  2. Assuming he knows better than you about who your users are and/or what your software does.

God I love the internet. 😂

mconigliaro avatar May 06 '22 17:05 mconigliaro