classification
Title: python creates IPv6 DNS requests even when built with --disable-ipv6
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Evan.Teran, giampaolo.rodola, loewis, schmir
Priority: normal Keywords:

Created on 2010-01-18 22:51 by Evan.Teran, last changed 2010-05-07 20:41 by giampaolo.rodola.

Messages (2)
msg98036 - (view) Author: Evan Teran (Evan.Teran) Date: 2010-01-18 22:51
I have encountered an issue where python will do a AAAA request even when built without IPv6. This becomes an issue because on some configurations this seems to cause a 5 second delay on DNS lookups (that is a separate issue of course). Basically here is what I am seeing:

#!/usr/bin/python
import urllib2
print urllib2.urlopen('http://python.org/').read(100)

results in the following:

0.000000  10.102.0.79 -> 8.8.8.8      DNS Standard query A python.org
  0.000023  10.102.0.79 -> 8.8.8.8      DNS Standard query AAAA python.org
  0.005369      8.8.8.8 -> 10.102.0.79  DNS Standard query response A 82.94.164.162
  5.004494  10.102.0.79 -> 8.8.8.8      DNS Standard query A python.org
  5.010540      8.8.8.8 -> 10.102.0.79  DNS Standard query response A 82.94.164.162
  5.010599  10.102.0.79 -> 8.8.8.8      DNS Standard query AAAA python.org
  5.015832      8.8.8.8 -> 10.102.0.79  DNS Standard query response AAAA 2001:888:2000:d::a2

looking at socket.py in create_connection() (line 500 on my python 2.6.4 stdlib) the code is like this:

    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                sock.settimeout(timeout)
            sock.connect(sa)
            return sock

        except error, msg:
            if sock is not None:
                sock.close()

The 3rd argument is the socket type, which is set to 0 which apparently means unspecified. It seems to me that if python is built without IPv6 support it should instead pass AF_INET since even if it does get an IPv6 response it can't possibly use it.
msg98037 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-01-18 23:13
Can you propose a patch?

I personally consider this not worth the effort. Unless there is a DNS problem, this cases shouldn't really be noticable, as the socket module will immediately report that IPv6 is not supported (without even consulting the operating system). So if there is a problem, it must be with DNS, in which case I would rather recommend to fix the DNS setup.
History
Date User Action Args
2010-05-07 20:41:07giampaolo.rodolasetnosy: + giampaolo.rodola
2010-05-07 20:36:13schmirsetnosy: + schmir
2010-01-18 23:15:23brian.curtinsetpriority: normal
versions: - Python 2.5
type: behavior
components: + Library (Lib), - None
stage: test needed
2010-01-18 23:13:46loewissetnosy: + loewis
messages: + msg98037
2010-01-18 22:51:38Evan.Terancreate