This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients Carlos.Ralli, Paul Marks, andreasr, berker.peksag, dazhaoyu, gregory.p.smith, jleedev, martin.panter, neologix, r.david.murray
Date 2016-08-03.02:07:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I also have reservations about using getaddrinfo() like this. Some potential problems:

1. IPv4-only compatibility: On my Linux computer, getaddrinfo("localhost", 0) returns AF_INET6 before AF_INET. Some programs, like Firefox and BSD netcat, will try both v4 and v6 and probably succeed (netcat first warned about “connection refused” for IPv4). However, other programs only support IPv4 at all or by default. Socat supports v6 but requires an explicit TCP6 or pf=ip6 argument. Gnu netcat only seems to support IPv4. This could also have been a problem with smtpd, or maybe SMTP clients are supposed to be smarter and it is okay (I am not familiar with the protocol).

2. Similarly, maybe getaddrinfo() could return AF_INET first even though the user made a subclass with address_family = AF_INET6.

3. It seems a waste to do a DNS lookup just to choose the address_family and throw away the resolved addresses, only to then call bind() which will do the lookup all over again. If DNS times out, the delay until error reporting will be twice as long.

4. getaddrinfo(("", None)) has a short delay (DNS timeout?) for me. The Python documentation says the empty string "" is special-cased to mean INADDR_ANY (IPv4). It also says there is no special case for the IPv6 equivalent (in6addr_any), although it does seem to work in some cases, including bind(). But getaddrinfo() would parse the string in the underlying platform, not in Python.

Some ideas:

1. Don’t look up hostnames, and only determine IPv6 if a numerical IP address is specified. I think this closer to the original proposal. Maybe use AI_NUMERICHOST? Or the simplistic test proposed in Issue 24209?

2. For the empty string address "", if the platform supports dual stack, use AF_INET6, bind to “::” and clear the IPV6_V6ONLY option. See Issue 3213.

3. Bind sockets to all addresses returned by getaddrinfo(), not just the first. But this would be a much bigger and more radical change. Maybe just something to dream about. :)

4. Add an address_family parameter to the constructor, so the user can change to AF_INET6 without subclassing.
Date User Action Args
2016-08-03 02:07:21martin.pantersetrecipients: + martin.panter, gregory.p.smith, r.david.murray, neologix, berker.peksag, jleedev, dazhaoyu, andreasr, Carlos.Ralli, Paul Marks
2016-08-03 02:07:21martin.pantersetmessageid: <>
2016-08-03 02:07:21martin.panterlinkissue20215 messages
2016-08-03 02:07:20martin.pantercreate