@@ -24,6 +24,7 @@ def initialize(env)
24
24
@definitions = { }
25
25
@nodes = { }
26
26
@notfound = { }
27
+ # always lock the environment before acquiring this lock
27
28
@lock = Puppet ::Concurrent ::Lock . new
28
29
29
30
# So we can keep a list and match the first-defined regex
@@ -185,26 +186,29 @@ def version
185
186
# Resolve namespaces and find the given object. Autoload it if
186
187
# necessary.
187
188
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?
200
208
end
201
- else
202
- fqname = munge_name ( fqname )
203
- result = loader . try_load_fqname ( type , fqname )
204
- @notfound [ fqname ] = result . nil?
205
209
end
210
+ result
206
211
end
207
- result
208
212
end
209
213
end
210
214
0 commit comments