Please review pull request #186: (#12790) Raise an exception if recursion is detected opened by (stschulte)
Description:
Facter can already detect fact dependency cycles (fact recursions).
Without this patch facter will return nil (or an already cached value)
as a factvalue when a recursion is detected. This can silently break
things. Example
Facter.add(:foo)
if Facter.value(:bar) != 'baz'
something happens here
end
end
If there is now a recursion when querying the bar fact we will always
execute the following codeblock (nil != baz). This may lead to strange
and inexplicable results for the foo fact.The fix now changes the behaviour when a recursion is detected: Do not
just print a debug message but throw an error. This way a recursion is
a lot easier to detect and we can actually fix it.
- Opened: Tue Mar 06 20:11:57 UTC 2012
- Based on: puppetlabs:master (15b857472a75caf9cd596c2b33d285577382293a)
- Requested merge: stschulte:feature/master/12790 (2e7a108d478b2f23a6344ef6b0f8f8c60bd15fa5)
Diff follows:
diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb
index d53a688..1b2e14e 100644
--- a/lib/facter/util/fact.rb
+++ b/lib/facter/util/fact.rb
@@ -100,16 +100,7 @@ def searching?
# Lock our searching process, so we never ge stuck in recursion.
def searching
- if searching?
- Facter.debug "Caught recursion on %s" % @name
-
- # return a cached value if we've got it
- if @value
- return @value
- else
- return nil
- end
- end
+ raise RuntimeError, "Caught recursion on #{@name}" if searching?
# If we've gotten this far, we're not already searching, so go ahead and do so.
@searching = true
diff --git a/spec/integration/facter_spec.rb b/spec/integration/facter_spec.rb
index 0c52895..c90c60d 100755
--- a/spec/integration/facter_spec.rb
+++ b/spec/integration/facter_spec.rb
@@ -24,4 +24,16 @@
Facter.reset
Facter.collection.should_not equal(old)
end
+
+ it "should raise an error if a recursion is detected" do
+ Facter.clear
+ Facter.add(:foo) do
+ confine :bar => 'some_value'
+ end
+ Facter.add(:bar) do
+ confine :foo => 'some_value'
+ end
+ lambda { Facter.value(:foo) }.should raise_error(RuntimeError, /Caught recursion on foo/)
+ end
+
end
-- 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.
