[talk] Is getaddrinfo thread-safe on OS X?

A. Jesse Jiryu Davis jesse at emptysquare.net
Tue Jan 12 21:05:28 EST 2016


With your help I've convinced myself that modern Mac OS X's getaddrinfo is
indeed thread-safe on version 10.10. I wrote up my findings in a CPython
bug report:

http://bugs.python.org/issue25924

Now I just need to get my hands on a machine running Mac OS X 10.4 and
confirm that getaddrinfo is NOT thread-safe there....

On Mon, Jan 4, 2016 at 9:00 AM, Steve <steve.b at osfda.org> wrote:

> Sometimes they do things like that for backlevel compatibility; so single
> threaded apps that rely on that global don't immediately break.
> The question is: does ds_getaddrinfo _rely_ on that variable?
>
> I doubt it; but it's _possible_ you found an oversight!
>
>
>
> On 1/3/2016 10:57 AM, A. Jesse Jiryu Davis wrote:
>
> Thanks for the pointers, with your help I'm making progress. I think I
> found the source for Apple's getaddrinfo.
>
> In Apple's Libinfo version 222.4.12, the man page says getaddrinfo isn't
> thread-safe:
>
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.3
>
> And here's its source:
>
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.c
>
> Glancing at the source naïvely, I might see the data race: getaddrinfo
> calls gai_lookupd, which reads and writes the global static variable
> "gai_proc". I can't see what will go wrong as a result of the race, but it
> sure LOOKS bad. =)
>
> In the next release, version 278, the thread-safety warning is gone from
> the man page:
>
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.3
>
> And getaddrinfo is largely rewritten:
>
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.c
>
> It calls a new function, "ds_getaddrinfo". But ds_getaddrinfo still
> accesses the global static variable "gai_proc"; I wonder why this is
> considered thread-safe now?
>
> On Sun, Jan 3, 2016 at 12:14 AM, Siobhan Lynch <slynch2112 at me.com> wrote:
>
>> OK… try and look at the revision histories of these three files:
>>
>>      *#include* *<sys/types.h>*
>>      *#include* *<sys/socket.h>*
>>      *#include* *<netdb.h>*
>>
>>
>> *-Trish*
>>
>>
>>
>
>
> _______________________________________________
> talk mailing listtalk at lists.nycbug.orghttp://lists.nycbug.org/mailman/listinfo/talk
>
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nycbug.org
> http://lists.nycbug.org/mailman/listinfo/talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nycbug.org/pipermail/talk/attachments/20160112/c6c84fa2/attachment.html>


More information about the talk mailing list