Skip to content

Commit 2e131b4

Browse files
authored
Merge pull request #8834 from joshcooper/mt_deadlock_11349
(PUP-11373) Always lock the environment before its type collection
2 parents ef4be52 + 0a626f1 commit 2e131b4

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/puppet/resource/type_collection.rb

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(env)
2424
@definitions = {}
2525
@nodes = {}
2626
@notfound = {}
27+
# always lock the environment before acquiring this lock
2728
@lock = Puppet::Concurrent::Lock.new
2829

2930
# So we can keep a list and match the first-defined regex
@@ -185,26 +186,29 @@ def version
185186
# Resolve namespaces and find the given object. Autoload it if
186187
# necessary.
187188
def find_or_load(name, type)
188-
@lock.synchronize do
189-
# Name is always absolute, but may start with :: which must be removed
190-
fqname = (name[0,2] == COLON_COLON ? name[2..-1] : name)
191-
192-
result = send(type, fqname)
193-
unless result
194-
if @notfound[ fqname ] && Puppet[ :ignoremissingtypes ]
195-
# do not try to autoload if we already tried and it wasn't conclusive
196-
# as this is a time consuming operation. Warn the user.
197-
# Check first if debugging is on since the call to debug_once is expensive
198-
if Puppet[:debug]
199-
debug_once _("Not attempting to load %{type} %{fqname} as this object was missing during a prior compilation") % { type: type, fqname: fqname }
189+
# always lock the environment before locking the type collection
190+
@environment.lock.synchronize do
191+
@lock.synchronize do
192+
# Name is always absolute, but may start with :: which must be removed
193+
fqname = (name[0,2] == COLON_COLON ? name[2..-1] : name)
194+
195+
result = send(type, fqname)
196+
unless result
197+
if @notfound[ fqname ] && Puppet[ :ignoremissingtypes ]
198+
# do not try to autoload if we already tried and it wasn't conclusive
199+
# as this is a time consuming operation. Warn the user.
200+
# Check first if debugging is on since the call to debug_once is expensive
201+
if Puppet[:debug]
202+
debug_once _("Not attempting to load %{type} %{fqname} as this object was missing during a prior compilation") % { type: type, fqname: fqname }
203+
end
204+
else
205+
fqname = munge_name(fqname)
206+
result = loader.try_load_fqname(type, fqname)
207+
@notfound[ fqname ] = result.nil?
200208
end
201-
else
202-
fqname = munge_name(fqname)
203-
result = loader.try_load_fqname(type, fqname)
204-
@notfound[ fqname ] = result.nil?
205209
end
210+
result
206211
end
207-
result
208212
end
209213
end
210214

0 commit comments

Comments
 (0)