From dcca844e9b73924a549afd7b26660f19df4a5b1f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 6 Dec 2021 12:22:42 -0500 Subject: [PATCH] Refresh eventlet resolver on resolv.conf change Eventlet holds on to stale resolv.conf. As a workaround, monitor resolv.conf and explicitly reinitialize greendns resolver. --- confluent_server/confluent/sockapi.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index 971c1738..53f76ed2 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -34,6 +34,7 @@ import traceback import eventlet.green.select as select import eventlet.green.socket as socket import eventlet.green.ssl as ssl +import eventlet.support.greendns as greendns import eventlet import confluent.auth as auth @@ -495,8 +496,22 @@ class SockApi(object): self.start_remoteapi() else: eventlet.spawn_n(self.watch_for_cert) + eventlet.spawn_n(self.watch_resolv) self.unixdomainserver = eventlet.spawn(_unixdomainhandler) + def watch_resolv(self): + while True: + watcher = libc.inotify_init1(os.O_NONBLOCK) + if libc.inotify_add_watch(watcher, b'/etc/resolv.conf', 0xcda) <= -1: + break + select.select((watcher,), (), (), 86400) + try: + os.read(watcher, 1024) + except Exception: + pass + greendns.resolver = greendns.ResolverProxy(hosts_resolver=greendns.HostsResolver()) + os.close(watcher) + def watch_for_cert(self): watcher = libc.inotify_init1(os.O_NONBLOCK) if libc.inotify_add_watch(watcher, b'/etc/confluent/', 0x100) > -1: