Skip to content

Commit

Permalink
Try not to trigger the GLIBC race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch authored and Megan Wilhite committed May 19, 2022
1 parent 391abc9 commit 3f07f00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/62071.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop trigering the `GLIBC race condition <https://sourceware.org/bugzilla/show_bug.cgi?id=19329>`_ when parallelizing the resolution of the fqnds.
24 changes: 16 additions & 8 deletions salt/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Module for gathering and managing network information
"""

import concurrent.futures
import datetime
import hashlib
import logging
import os
import re
import socket
import time
from concurrent.futures import ThreadPoolExecutor

import salt.utils.decorators.path
import salt.utils.functools
Expand Down Expand Up @@ -2084,7 +2084,6 @@ def fqdns():
HOST_NOT_FOUND = 1
NO_DATA = 4

grains = {}
fqdns = set()

def _lookup_fqdn(ip):
Expand Down Expand Up @@ -2115,14 +2114,23 @@ def _lookup_fqdn(ip):
# when the "fqdn" is not defined for certains IP addresses, which was
# causing that "socket.timeout" was reached multiple times sequentially,
# blocking execution for several seconds.

try:
with ThreadPoolExecutor(8) as pool:
for item in pool.map(_lookup_fqdn, addresses):
if item:
fqdns.update(item)
with concurrent.futures.ThreadPoolExecutor(8) as pool:
future_lookups = {
pool.submit(_lookup_fqdn, address): address for address in addresses
}
for future in concurrent.futures.as_completed(future_lookups):
address = future_lookups[future]
try:
resolved_fqdn = future.result()
if resolved_fqdn:
fqdns.update(resolved_fqdn)
except Exception as exc: # pylint: disable=broad-except
log.error("Failed to resolve address %s: %s", address, exc)
except Exception as exc: # pylint: disable=broad-except
log.error("Exception while creating a ThreadPool for resolving FQDNs: %s", exc)
log.error(
"Exception while creating a ThreadPoolExecutor for resolving FQDNs: %s", exc
)

elapsed = time.time() - start
log.debug("Elapsed time getting FQDNs: %s seconds", elapsed)
Expand Down

0 comments on commit 3f07f00

Please sign in to comment.