From 8f7c33d7fb591f48a73668a8b1e1432cd3433645 Mon Sep 17 00:00:00 2001 From: Marek Czernek Date: Mon, 4 Mar 2024 11:27:35 +0100 Subject: [PATCH] Make importing seco.range thread safe (bsc#1211649) --- salt/roster/range.py | 5 +++++ salt/utils/roster_matcher.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/salt/roster/range.py b/salt/roster/range.py index 0633d56e389e..247fb51ced61 100644 --- a/salt/roster/range.py +++ b/salt/roster/range.py @@ -15,16 +15,21 @@ import fnmatch import logging +import salt.loader + log = logging.getLogger(__name__) # Try to import range from https://github.com/ytoolshed/range HAS_RANGE = False try: + salt.loader.LOAD_LOCK.acquire() import seco.range HAS_RANGE = True except ImportError: log.warning("Unable to load range library") +finally: + salt.loader.LOAD_LOCK.release() # pylint: enable=import-error diff --git a/salt/utils/roster_matcher.py b/salt/utils/roster_matcher.py index c424c63bb0e9..39e57f78f171 100644 --- a/salt/utils/roster_matcher.py +++ b/salt/utils/roster_matcher.py @@ -8,14 +8,19 @@ import logging import re +import salt.loader + # Try to import range from https://github.com/ytoolshed/range HAS_RANGE = False try: + salt.loader.LOAD_LOCK.acquire() import seco.range HAS_RANGE = True except ImportError: pass +finally: + salt.loader.LOAD_LOCK.release() # pylint: enable=import-error