From e7ba89c30fe9cd1127636eee11e56fd1eb2dff43 Mon Sep 17 00:00:00 2001 From: Bernd Helm Date: Fri, 20 Jun 2014 18:25:56 +0200 Subject: [PATCH] clear /etc/resolv.conf cache on posix systems when reattempting connection --- sleekxmpp/xmlstream/xmlstream.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 66985f3d7..c49e7683e 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -27,6 +27,8 @@ import weakref import uuid import errno +import os +import ctypes from xml.parsers.expat import ExpatError @@ -477,6 +479,15 @@ def _connect(self, reattempt=True): except SystemExit: self.set_stop() return False + if os.name is 'posix': + # libc caches /etc/resolv.conf. try to flush the cache, see https://github.com/fritzy/SleekXMPP/issues/298 + try: + log.debug("flushing /etc/resolv.conf cache") + libc = ctypes.CDLL('libc.so.6') + res_init = getattr(libc, '__res_init') + res_init(None) + except: + log.debug('Error calling libc.__res_init') if self.default_domain: try: