six-pack / Axis-Mundi

A secure, resilient, distributed and open communication platform.
59 stars 21 forks source link

socket.error: [Errno 98] Address already in use #12

Closed dreboli closed 9 years ago

dreboli commented 9 years ago

Sometimes CTRL+C doesn't kill client.py properly, it stucks listening on the socks port and the client can't be started again because of that.

Trying to start client.py again throws:

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Traceback (most recent call last):
  File "./client.py", line 657, in <module>
    app.run(debug=True,threaded=True) # Enable threading, primarily for pks keyserver support until the keyserver is moved to client_backend
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 618, in run_simple
    test_socket.bind((hostname, port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

I can't replicate the problem yet, not sure if a clean(er) exit is possible or beneficial, just throwing it out here as I've ran into this a couple of times.

This is how I check what's listening on the socks port:

$ lsof -i :9150
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python  2687 user    4u  IPv4  61888      0t0  TCP localhost:46580->localhost:9150 (ESTABLISHED)

And to kill it:

$ kill -9 2687

where 2687 is the PID. Without -9 it can't be killed

six-pack commented 9 years ago

Thanks again @dreboli

Yes this issue started when I switched Flask to use threading (see the very last line of client.py) which is: app.run(debug=True,threaded=True)

I get it quite a alot and its very annoying especially becasue I am constantly restarting the software. One of the flask threads is not exiting for some reason under certain circumstances. The client-backend thread does exit cleanly but for some reason flask doesn't and remains bound to port 5000 which casues a problem when you re-run the client which of course wants to listen on port 5000.

Adding it to the bugfix list

six-pack commented 9 years ago

This one is turning out to be quite elusive If you hit log-out before shutting down the client it usually works ok.

Trying to stop and restart the client whenlogged in will sometimes give you this error. I played with SOREUSEADDR and PORT but then started getting a much bigger problem which is some requests being serviced by the old process and some by the new, very bad.

So for now I will fix this by adding a log-out and shutdown option on the menu.

six-pack commented 9 years ago

This is fixed by the recent commit 161716b092e37d55cd8b7539f13ac0ae773bdeea

This commit introduces a launcher which forks the client front-end Flask thread. Clean up and the end is better.

Problem appears resolved on Linux and WIndows so closing.

Thanks again @dreboli