[Sugar-devel] Reset the resolver cache after bringing up the network

James Cameron quozl at laptop.org
Wed May 12 21:37:15 EDT 2010

On Wed, May 12, 2010 at 03:18:07PM -0400, Martin Langhoff wrote:
> Clearly, some python lib caches stale DNS resolver data, and refuses
> to let go, but we didn't know where the problem was.

I've sussed it.  libc and Python.  Consider this reproducer, which uses
the same underlying library methods that the registration menu item

1.  disconnect from wireless on the laptop (oh, you need my patch for
that (SL #1608), but 1.5 current builds have it),

2.  in Terminal start a python instance and run this;

	import socket
	x = socket.create_connection(('google.com', 80))

you will get "socket.gaierror: [Errno -3] Temporary failure in name
resolution", because /etc/resolv.conf is empty,

3.  connect to a working network,

4.  repeat the socket.create_connection() call without restarting the
python process, you will get the same error,

5.  exit the python instance and start another, you won't get the error.

The cause of the problem is that /etc/resolv.conf is not re-read by
libc.  We could fix it by moving to Ubuntu, which stat()s resolv.conf to
detect change.  ;-)

> The anaconda folks have just hit the same prob, and fixed it. We
> probably need to do the same on the appropriate NM event...

Similar problem, very different solution, since another resolver is

jarabe.desktop.schoolserver.register_laptop() calls
xmlrpclib.ServerProxy() which calls
xmlrpclib.Transport.make_connection() which calls
httplib.HTTPConnection.connect() which calls
socket.create_connection() with the hostname.

I've not yet figured a way to call res_init() from python.  ;-(

James Cameron

More information about the Devel mailing list