Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-04-19 20:26:49 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-04-19 20:26:49 (GMT)
commit2f2dd3fd1a474d01c7bb189a73c0a96702c87ca4 (patch)
treea519f6e5845ac3383422a22cc0fe60c7139c5478
parentbbc2345690e5dea13b8d2e6b3ef7740c3222568a (diff)
Reset c-ares resolver on network reconnection
-rw-r--r--sugar_network/client/commands.py3
-rw-r--r--sugar_network/toolkit/coroutine.py4
-rw-r--r--sugar_network/toolkit/util.py19
3 files changed, 5 insertions, 21 deletions
diff --git a/sugar_network/client/commands.py b/sugar_network/client/commands.py
index d9c89be..a81a91c 100644
--- a/sugar_network/client/commands.py
+++ b/sugar_network/client/commands.py
@@ -329,8 +329,7 @@ class ClientCommands(db.CommandsProcessor, Commands, journal.Commands):
while coroutine.select([monitor.fileno()], [], [], 1)[0]:
monitor.read()
self._node_job.kill()
- # Otherwise, `socket.gethostbyname()` will return stale resolve
- util.res_init()
+ coroutine.reset_resolver()
def _remote_connect(self):
diff --git a/sugar_network/toolkit/coroutine.py b/sugar_network/toolkit/coroutine.py
index 0c40fac..64b7cf5 100644
--- a/sugar_network/toolkit/coroutine.py
+++ b/sugar_network/toolkit/coroutine.py
@@ -47,6 +47,10 @@ def shutdown():
return _group.join()
+def reset_resolver():
+ gevent.get_hub().resolver = None
+
+
def socket(*args, **kwargs):
import gevent.socket
return gevent.socket.socket(*args, **kwargs)
diff --git a/sugar_network/toolkit/util.py b/sugar_network/toolkit/util.py
index 35d37d6..3c1ffc9 100644
--- a/sugar_network/toolkit/util.py
+++ b/sugar_network/toolkit/util.py
@@ -175,25 +175,6 @@ def readline(stream, limit=None):
return bytes(line)
-def res_init():
- """Reset resolving cache.
-
- Calling this function will enforce libc to avoid using stale resolving
- cache after getting [re]connected. For example, if application process
- was launched when there were no any DNS servers available, after getting
- connected, call `res_init()` to reuse newly appeared DNS servers.
-
- """
- import ctypes
- from ctypes.util import find_library
- try:
- lib_name = find_library('c')
- libc = ctypes.CDLL(lib_name)
- getattr(libc, '__res_init')(None)
- except Exception:
- _logger.exception('Failed to call res_init()')
-
-
def default_route_exists():
with file('/proc/self/net/route') as f:
# Skip header