[Python-Dev] Need help with the slow bind on Mac OS X problem

Skip Montanaro skip@pobox.com
Mon, 21 Jul 2003 16:56:14 -0500


I need some help with <http://python.org/sf/774751>.  Jack assigned it to
me.  I'll take a stab at it, but I need a bit of guidance from someone who
understands the code a bit better.  In particular, there are two chunks of
code near the top of socketmodule.c which seem to be interfering with my
attempts to craft a fix.

First, there's code to determine whether or not the lock is required:

    /* On systems on which getaddrinfo() is believed to not be thread-safe,
       (this includes the getaddrinfo emulation) protect access with a lock. */
    #if defined(WITH_THREAD) && (defined(__APPLE__) || defined(__FreeBSD__) || \
        defined(__OpenBSD__) || defined(__NetBSD__) || !defined(HAVE_GETADDRINFO))
    #define USE_GETADDRINFO_LOCK
    #endif

    #ifdef USE_GETADDRINFO_LOCK
    #define ACQUIRE_GETADDRINFO_LOCK PyThread_acquire_lock(netdb_lock, 1);
    #define RELEASE_GETADDRINFO_LOCK PyThread_release_lock(netdb_lock);
    #else
    #define ACQUIRE_GETADDRINFO_LOCK
    #define RELEASE_GETADDRINFO_LOCK
    #endif

This is fine as far as it goes I suspect, however, later on, in certain
cases HAVE_GETADDRINFO is #undef'd:

    #ifdef __APPLE__
    /* On OS X, getaddrinfo returns no error indication of lookup
       failure, so we must use the emulation instead of the libinfo
       implementation. Unfortunately, performing an autoconf test
       for this bug would require DNS access for the machine performing
       the configuration, which is not acceptable. Therefore, we
       determine the bug just by checking for __APPLE__. If this bug
       gets ever fixed, perhaps checking for sys/version.h would be
       appropriate, which is 10/0 on the system with the bug. */
    #ifndef HAVE_GETNAMEINFO
    /* This bug seems to be fixed in Jaguar. Ths easiest way I could
       Find to check for Jaguar is that it has getnameinfo(), which
       older releases don't have */
    #undef HAVE_GETADDRINFO
    #endif
    #endif

I am running 10.2.6 (Jaguar), so compilation doesn't reach the #undef
directive.  This means I'm not using the fake_getaddrinfo, however I still
have the *_GETADDRINFO_LOCKs defined.

It seems to me that perhaps the fake_getaddrinfo code should be used on Mac
OS X in all cases.  Either it's < 10.2.6 and thus has a broken getaddrinfo,
or its >= 10.2.6 in which case it still has a getaddrinfo which is likely
not to be thread-safe.

That requires more restructuring of socketmodule.c's tests than I'm
comfortable with at this late date.  I will try to craft a patch and attach
it to the above tracker item, but I need some people to both look at it and
try it out.

Thanks,

Skip