Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

clear /etc/resolv.conf cache on posix systems when reattempting connection #299

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions sleekxmpp/xmlstream/xmlstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import weakref
import uuid
import errno
import os
import ctypes

from xml.parsers.expat import ExpatError

Expand Down Expand Up @@ -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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail for FreeBSD 9.2, but will succeed if you specify just 'libc.so', but both variants will fail for FreeBSD 10 where 'libc.so.7' is needed. May be figure out some more solid solution to find out right 'lib.so'?

res_init = getattr(libc, '__res_init')
res_init(None)
except:
log.debug('Error calling libc.__res_init')

if self.default_domain:
try:
Expand Down