Skip to content

Commit

Permalink
Sleep before trying to resolve instead
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch authored and Megan Wilhite committed May 19, 2022
1 parent fd4e389 commit cd5905f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions salt/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cd5905f

Please sign in to comment.