The autoloading is not thread safe, which means two threads could both autoload the same function at the same time.
Signed-off-by: Brice Figureau <[email protected]> --- lib/puppet/parser/functions.rb | 6 ++++-- spec/integration/parser/functions_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 spec/integration/parser/functions_spec.rb diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index b0deac5..5807c0b 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -73,8 +73,10 @@ module Puppet::Parser::Functions def self.function(name) name = symbolize(name) - unless functions.include?(name) or functions(Puppet::Node::Environment.root).include?(name) - autoloader.load(name,Environment.current || Environment.root) + @functions.synchronize do + unless functions.include?(name) or functions(Puppet::Node::Environment.root).include?(name) + autoloader.load(name,Environment.current || Environment.root) + end end ( functions(Environment.root)[name] || functions[name] || {:name => false} )[:name] diff --git a/spec/integration/parser/functions_spec.rb b/spec/integration/parser/functions_spec.rb new file mode 100644 index 0000000..cbfb4ac --- /dev/null +++ b/spec/integration/parser/functions_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Parser::Functions do + before :each do + Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.function("template") + end + + it "should support multiple threads autoloading the same function" do + threads = [] + lambda { + 10.times { |a| + threads << Thread.new { + Puppet::Parser::Functions.function("template") + } + } + }.should_not raise_error + threads.each { |t| t.join } + end +end \ No newline at end of file -- 1.7.2.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
