Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to start devlopment server -- BindError: Unable to find a consistent port localhost

Google-app-engine development server runs great yesterday, but when I try to start it today. It only shout out this Error.

I tried use lsof -i:8080 / lsof -i:8000 to make sure these ports are not taken. I also tried use a --port arg to switch to another port. I even removed the gae folder and installed a new one. -- with no luck at all.

Maybe there is a obvious solution but I can't see it.

Here is the Oh-My-God trace stack..

Traceback (most recent call last):
File "/home/henry/software/google_appengine/dev_appserver.py", line 182, in <module>
        _run_file(__file__, globals())
File "/home/henry/software/google_appengine/dev_appserver.py", line 178, in _run_file
        execfile(script_path, globals_)
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 689, in <module>
        main()
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 682, in main
        dev_server.start(options)
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 653, in start
        apis.start()
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 152, in start
        super(APIServer, self).start()
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 294, in start
        raise BindError('Unable to find a consistent port %s' % host)
    google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to find a consistent port localhost
    Exception in thread Thread-4 (most likely raised during interpreter shutdown):
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
      File "/usr/lib/python2.7/threading.py", line 763, in runhenry@henry-A
like image 378
Henry.T Avatar asked May 22 '13 09:05

Henry.T


4 Answers

This can be caused by multiple entries in your hosts file for 'localhost'.

For example in file /etc/hosts:

127.0.0.1 localhost
127.0.0.1 mymachinename localhost

if you delete all mappings but one for localhost, the problem will hopefully be resolved.

127.0.0.1 mymachinename localhost

This is a known issue and as far as I understand it will be corrected in a future release.

like image 107
user2410920 Avatar answered Nov 01 '22 00:11

user2410920


While I never seen that before try running it on a different port or even using a different host:

dev_appserver.py /path/to/project --port 8888 --host 127.0.0.1

Where for host add your current IP address.

like image 42
Lipis Avatar answered Oct 31 '22 22:10

Lipis


Similar to what was posted, I had this issue and fixed it by altering the hosts file. The issue was with IPv6 addresses redirecting to localhost:

In my hosts file I had

127.0.0.1    localhost
::1          localhost 
fe80::1%lo0  localhost

And I commented out the IPv6 addresses to give

127.0.0.1     localhost
#::1          localhost 
#fe80::1%lo0  localhost

I'm not sure this is a viable permanent solution as I imagine it's important to have the IPv6 numerical addresses for localhost to be in the hosts file but it works for now until a proper fix is released.

like image 2
Sean Abraham Avatar answered Oct 31 '22 23:10

Sean Abraham


I suppose there is a bug in the google app engine. I debuged appengine/tools/devappserver2/wsgi_server.py, and here is the facts: 1. it runs fine when internet is disconnected 2. it shows such error when internet is on.

280 addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
281                                     socket.SOCK_STREAM, 0, socket.AI_PASSIVE)

In this piece of code, if you connect internet, addrinfo will only have the address in public internet. even you assign port and host in command line. Then you have no chance to bind this socket to localhost, since the address you bind is the public address you are using now.

In order to solve it, I just change the code into

280 addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
281                                     socket.SOCK_STREAM, 1, socket.AI_PASSIVE)

It works well now, I didn't check the code about socket.getaddrinfo, however, I suppose that it functions as ignoring the lookup address or not according to the integer 0 or 1.

Btw, I am using MacOs, there could be system dependency problem as well, if this is the case, then socket package should redesign somehow.

like image 1
phoenixgrey Avatar answered Nov 01 '22 00:11

phoenixgrey