"localhost" in config file mistakenly causes IP6 socket on Mac OS
Details: CherryPy 3.01, Mac OS 10.4.10, Python 2.51 (compiled from src)
The tutorial sample tut01_helloworld.py starts up normally with this message:
[29/Jul/2007:02:18:32] HTTP Serving HTTP on http://localhost:8080/
But that address fails to load in the browser. Firefox displays "Unable to connect. Firefox can't establish a connection to the server at localhost:8080."
After poking around a bit, I discovered that CP was mistakenly using IP6 sockets. Typing the address "http://[::1]:8080/" into Firefox DOES load the "Hello world!" page.
So here's what I think is happening. In _cpserver.py, line 213:
for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res
socket.getaddrinfo() is resolving "localhost" as an IP6 hostname instead of IP4. I don't know why this would happen, but it's probably specific to Mac OS. For what it's worth, there is no AF_UNSPEC defined in the socket.py file in my python installation.
Changing the config file to a numeric hostname fixes the problem, as follows:
server.socket_host = "127.0.0.1"
Perhaps a fix should put more robust code around the getaddrinfo() call to ensure that the correct socktype is returned on OS's with this quirk.
Reported by email@example.com