bind_unused_port raising gaierror: [Errno 8] #777

Merged
merged 1 commit into from May 9, 2013

Projects

None yet

2 participants

@mauriciosl

bind_unused_port was passing 0 as port number to the socket module.
This generated some exceptional behaviour on systems where nslookup of
localhost didn't returned the loopback interface.

This commit changes it to pass None instead, this will pass NULL to the underlying C API[1].

[1] http://docs.python.org/2.7/library/socket.html#socket.getaddrinfo

Mauricio Souza Lima change bind_unused_port to pass None as port
bind_unused_port was passing 0 as port number to the socket module.
This generated some exceptional behaviour on systems where nslookup of
localhost didn't returned the loopback interface.
dceb544
@bdarnell
tornadoweb member

This change looks fine. Out of curiosity, what platform was having trouble with the zero? All the ones I can easily test seem to treat 0 and None the same, whether the hostname specifies the loopback interface or not.

@bdarnell bdarnell merged commit 833fb21 into tornadoweb:master May 9, 2013

1 check passed

Details default The Travis CI build passed
@mauriciosl

Mac osx with python 2.7.2

mlima:~ mauricio.lima $ uname -a
Darwin mlima.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64

Thanks for accepting the patch ;)

@bdarnell
tornadoweb member

Interesting. FWIW it works for me on the mac. I'm using OSX 10.8, but my kernel version shows up as 12.3:
Darwin gonzo.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64

@mauriciosl

My corporate wifi has a problem where the nslookup for localhost brings another host instead of my own:

$ nslookup localhost
Server:       10.2.130.52
Address:  10.2.130.52#53

Name: localhost.glb.com
Address: 10.2.48.26

Under this condition, the tests fails with this message:

Traceback (most recent call last):
  File "tornado/testing.py", line 294, in setUp
    sock, port = bind_unused_port()
  File "tornado/testing.py", line 80, in bind_unused_port
    [sock] = netutil.bind_sockets(0, 'localhost', family=socket.AF_INET)
  File "tornado/netutil.py", line 85, in bind_sockets
    sock.bind(sockaddr)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 49] Can't assign requested address

If i edit my resolv.conf and take off the domain so that it doesn't look for localhost.glb.com, the error changes to:

Traceback (most recent call last):
  File "tornado/testing.py", line 294, in setUp
    sock, port = bind_unused_port()
  File "tornado/testing.py", line 80, in bind_unused_port
    [sock] = netutil.bind_sockets(0, 'localhost', family=socket.AF_INET)
  File "tornado/netutil.py", line 67, in bind_sockets
    0, flags)):
gaierror: [Errno 8] nodename nor servname provided, or not known

I know that it's a very narrow situation, and i'm sad that my network works this way :(.

@pombredanne pombredanne pushed a commit to pombredanne/urllib3 that referenced this pull request Nov 2, 2013
@shazow shazow Fixed tests for OSX 10.6. d7a72ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment