From d24504e83acd0bf210fb643d6c9f0cc2e6eae6c0 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 18 Aug 2008 19:15:24 -0500 Subject: Added a Process.waitall thread when there's a timeout, to avoid zombies. Without this call, every time there's a timeout, we'll get a zombie. --- CHANGELOG | 2 ++ lib/facter/util/resolution.rb | 5 +++++ spec/unit/util/resolution.rb | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index af190c6..6ddf9d4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ 1.5.x: + Added a Process.waitall thread when there's a timeout, to avoid zombies. + Set the timeout the host-based and resolve-based resolutions to 2. Fixed #1495 - CentOS version detection is now better. diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 19f2c1e..b50c9e9 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -121,6 +121,11 @@ class Facter::Util::Resolution end rescue Timeout::Error => detail warn "Timed out seeking value for %s" % self.name + + # This call avoids zombies -- basically, create a thread that will + # dezombify all of the child processes that we're ignoring because + # of the timeout. + Thread.new { Process.waitall } return nil end diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution.rb index 5ce3d63..643be33 100755 --- a/spec/unit/util/resolution.rb +++ b/spec/unit/util/resolution.rb @@ -112,6 +112,17 @@ describe Facter::Util::Resolution do @resolve.value.should be_nil end + + it "should waitall to avoid zombies if the timeout is exceeded" do + @resolve.stubs(:warn) + @resolve.timeout = 0.1 + @resolve.setcode { sleep 2; raise "This is a test" } + + Thread.expects(:new).yields + Process.expects(:waitall) + + @resolve.value + end end end -- cgit