From adef57abb4da47ebb41358a5c1f89c0ef1cb5afe Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 17 May 2022 18:43:59 +0100 Subject: [PATCH] Try not to trigger the GLIBC race condition. See https://sourceware.org/bugzilla/show_bug.cgi?id=19329 Fixes #62071 Signed-off-by: Pedro Algarvio --- changelog/62071.fixed | 1 + salt/modules/network.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 changelog/62071.fixed diff --git a/changelog/62071.fixed b/changelog/62071.fixed new file mode 100644 index 000000000000..3131569cb000 --- /dev/null +++ b/changelog/62071.fixed @@ -0,0 +1 @@ +Stop trigering the `GLIBC race condition `_ when parallelizing the resolution of the fqnds. diff --git a/salt/modules/network.py b/salt/modules/network.py index 763426c59cfa..971171dd6894 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -2,6 +2,7 @@ Module for gathering and managing network information """ +import concurrent.futures import datetime import hashlib import logging @@ -9,7 +10,6 @@ import re import socket import time -from concurrent.futures import ThreadPoolExecutor import salt.utils.decorators.path import salt.utils.functools @@ -2084,7 +2084,6 @@ def fqdns(): HOST_NOT_FOUND = 1 NO_DATA = 4 - grains = {} fqdns = set() def _lookup_fqdn(ip): @@ -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)