summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-09-11 08:30:34 -0700
committerdanielsdeleo <dan@opscode.com>2013-09-11 08:30:34 -0700
commitebe7f8e87349655ba2601a3b18c4711fd95c6bf5 (patch)
treed332fb8ac53c3d14e8e8aae5bcaf115309630f1b
parent89f7f802e3bc5ab92c32eff7f065acdebff8492c (diff)
downloadmixlib-shellout-ebe7f8e87349655ba2601a3b18c4711fd95c6bf5.tar.gz
Use blocking waitpid only on ENOENT
This is a compromise that prevents us from leaving zombie processes around after a failed exec raises ENOENT, but prevents us from blocking (possibly forever) on timed-out commands. The latter case can cause zombies, so this is not optimal for all cases. See MIXLIB-16 for a proposed enhancement to solve that case.
-rw-r--r--lib/mixlib/shellout/unix.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index af3e421..d7b8b92 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -82,10 +82,18 @@ module Mixlib
end
end
self
- rescue Exception
- # do our best to kill zombies
+ rescue Errno::ENOENT
+ # When ENOENT happens, we can be reasonably sure that the child process
+ # is going to exit quickly, so we use the blocking variant of waitpid2
Process.waitpid2(@child_pid) rescue nil
raise
+ rescue Exception
+ # For exceptions other than ENOENT, such as timeout, we can't be sure
+ # how long the child process will live, so we use the non-blocking
+ # variant of waitpid2. This can result in zombie processes when the
+ # child later dies. See MIXLIB-16 for proposed enhancement.
+ Process.waitpid2(@child_pid, Process::WNOHANG) rescue nil
+ raise
ensure
# no matter what happens, turn the GC back on, and hope whatever busted
# version of ruby we're on doesn't allocate some objects during the next