From cd5905f7ec27207b650c7a48791dc66f2d2b8e85 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 18 May 2022 11:44:44 +0100 Subject: [PATCH] Sleep before trying to resolve instead Signed-off-by: Pedro Algarvio --- salt/modules/network.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/salt/modules/network.py b/salt/modules/network.py index a690d3b1fde5..bea9b49e6c52 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -2094,6 +2094,11 @@ def fqdns(): fqdns = set() def _lookup_fqdn(ip): + # Random sleep between 0.025 and 0.050 to avoid hitting + # the GLIBC race condition. + # For more info, see: + # https://sourceware.org/bugzilla/show_bug.cgi?id=19329 + time.sleep(random.randint(25, 50) / 1000) try: return [socket.getfqdn(socket.gethostbyaddr(ip)[0])] except socket.herror as err: @@ -2123,14 +2128,9 @@ def _lookup_fqdn(ip): # blocking execution for several seconds. try: with concurrent.futures.ThreadPoolExecutor(8) as pool: - future_lookups = {} - for address in addresses: - future_lookups[pool.submit(_lookup_fqdn, address)] = address - # Random sleep between 0.025 and 0.050 to avoid hitting - # the GLIBC race condition. - # For more info, see: - # https://sourceware.org/bugzilla/show_bug.cgi?id=19329 - time.sleep(random.randint(25, 50) / 1000) + future_lookups = { + pool.submit(_lookup_fqdn, address): address for address in addresses + } for future in concurrent.futures.as_completed(future_lookups): try: resolved_fqdn = future.result()