Long entries in /etc/hosts cause long hangs in system resolver

Originator:james.abley
Number:rdar://13281763 Date Originated:2013-02-24
Status:Open Resolved:
Product:Mac OS X Product Version:10.8.2
Classification:Serious Bug Reproducible:Always
 
Summary:

Sufficiently long entries in the system hosts file cause long hangs in
system resolver operation, resulting in an effective maximum of 11
entries per line in the hosts file.

Steps to Reproduce:

1. Add an entry to /etc/hosts with N hostname entries, where N >= 12.
For example:

  echo '1.2.3.4 bar0 bar1 bar2 bar3 bar4 bar5 bar6 bar7 bar8 bar9
bar10 bar11' | sudo tee -a /etc/hosts >/dev/null

2. Attempt to resolve the second to (N - 10)th entries via gethostbyname:

  python -c 'import socket; print socket.gethostbyname("bar1")'

Expected Results:

Near instant resolution, returning "1.2.3.4"

Actual Results:

Long hangs in the syscall, up to 40 seconds in duration, before
returning the correct response:

    $ time python -c 'import socket; print socket.gethostbyname("bar1")'
    1.2.3.4
    0.03s user 0.01s system 0% cpu 4532M memory 35.047 total
    $ time python -c 'import socket; print socket.gethostbyname("bar1")'
    1.2.3.4
    0.03s user 0.01s system 0% cpu 4532M memory 35.043 total
    $ time python -c 'import socket; print socket.gethostbyname("bar1")'
    1.2.3.4
    0.03s user 0.01s system 0% cpu 4532M memory 35.047 total
    $ time ruby -e "require 'socket'; p Socket.gethostbyname('bar1')"
    ["bar0", [], 2, "\x01\x02\x03\x04"]

    real	0m35.063s
    user	0m0.034s
    sys	0m0.025s

Regression:

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!