cs01 / cs01/gdbgui

If gdbgui is going to open a browser window, it shouldn't die on port collision

Open
#189 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10.4k
Forks
521
PR merge metrics
No merged PRs in 30d

Description

##### Describe the issue

When the user doesn't explicitly specify a port, gdbgui's default behaviour is to try port 5000 and then die if it fails to bind. This is at odds with established convention in other such tools:

Specifically, when operating in a mode which spawns its own browser window, it is convention for a "local app with a browser UI" to plan for the possibility of port collisions... commonly, at minimum, by choosing one at random. (An example of this would be [restview](https://mg.pov.lt/restview/).)

I think it would make more sense for the current behaviour to be divided such that options such as `--remote` and `--no_browser` preserve the current failure mode while configurations which open a browser window automatically would gracefully handle a failure to bind port 5000... at the very least, by retrying with a random port if `5000` fails.

##### Steps to replicate

* Launch something else which binds to port 5000 by default
* Launch gdbgui
* Watch as you're left with an error message in the terminal and a newly-opened browser window/tab pointing at the other application

```
Opening gdbgui in browser at http://127.0.0.1:5000
exit gdbgui by pressing CTRL+C
Traceback (most recent call last):
File "/usr/local/bin/gdbgui", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/gdbgui/backend.py", line 907, in main
certificate=args.cert,
File "/usr/local/lib/python2.7/dist-packages/gdbgui/backend.py", line 241, in setup_backend
**kwargs
File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 556, in run
self.wsgi_server.serve_forever()
File "/usr/local/lib/python2.7/dist-packages/gevent/baseserver.py", line 360, in serve_forever
self.start()
File "/usr/local/lib/python2.7/dist-packages/gevent/baseserver.py", line 304, in start
self.init_socket()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 1450, in init_socket
StreamServer.init_socket(self)
File "/usr/local/lib/python2.7/dist-packages/gevent/server.py", line 127, in init_socket
self.socket = self.get_listener(self.address, self.backlog, self.family)
File "/usr/local/lib/python2.7/dist-packages/gevent/server.py", line 138, in get_listener
return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family)
File "/usr/local/lib/python2.7/dist-packages/gevent/server.py", line 229, in _tcp_listener
sock.bind(address)
File "", line 1, in bind
socket.error: [Errno 98] Address already in use: ('127.0.0.1', 5000)
```

##### Describe your environment
* Operating system and version: Kubuntu Linux 14.04 LTS
* gdbgui version (`gdbgui -v`): 0.11.3.0
* gdb version (`gdb -v`): GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
* browser: Mozilla Firefox 52 ESR
* python packages (`pip freeze`): It's quite a long list. I'll add it if you think it's relevant.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.