From e26ebb0b7254e5dec90ba7189c95b593b7d1fa55 Mon Sep 17 00:00:00 2001 From: John Stange Date: Tue, 19 Mar 2024 10:04:14 -0400 Subject: [PATCH] Pops::Loaders thread safety: synchronization in find_loader and [] --- lib/puppet/pops/loaders.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/puppet/pops/loaders.rb b/lib/puppet/pops/loaders.rb index 873b99e5e82..32b27f28af9 100644 --- a/lib/puppet/pops/loaders.rb +++ b/lib/puppet/pops/loaders.rb @@ -192,13 +192,15 @@ def self.loaders # @return [Loader] the found loader # @raise [Puppet::ParserError] if no loader is found def [](loader_name) - loader = @loaders_by_name[loader_name] - if loader.nil? + environment.lock.synchronize do + loader = @loaders_by_name[loader_name] + if loader.nil? # Unable to find the module private loader. Try resolving the module - loader = private_loader_for_module(loader_name[0..-9]) if loader_name.end_with?(' private') - raise Puppet::ParseError, _("Unable to find loader named '%{loader_name}'") % { loader_name: loader_name } if loader.nil? + loader = private_loader_for_module(loader_name[0..-9]) if loader_name.end_with?(' private') + raise Puppet::ParseError, _("Unable to find loader named '%{loader_name}'") % { loader_name: loader_name } if loader.nil? + end + loader end - loader end # Finds the appropriate loader for the given `module_name`, or for the environment in case `module_name` @@ -214,13 +216,13 @@ def find_loader(module_name) public_environment_loader else # TODO : Later check if definition is private, and then add it to private_loader_for_module - # - loader = public_loader_for_module(module_name) - if loader.nil? - raise Puppet::ParseError, _("Internal Error: did not find public loader for module: '%{module_name}'") % { module_name: module_name } + environment.lock.synchronize do + loader = public_loader_for_module(module_name) + if loader.nil? + raise Puppet::ParseError, _("Internal Error: did not find public loader for module: '%{module_name}'") % { module_name: module_name } + end + loader end - - loader end end