Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pops::Loaders thread safety: synchronization in find_loader and [] #9299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/puppet/pops/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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

Expand Down