From 8e77a79241a10fd0b4abcb183bc65c03083d4eec Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 14 Jun 2013 11:18:09 -0700 Subject: close observed to throw EBADF - Unsure how File.for_fd() succeeds and then then #close on the File throws this, but it must be racing with something. I don't think we care. --- lib/mixlib/shellout/unix.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb index bd20ffb..55a0372 100644 --- a/lib/mixlib/shellout/unix.rb +++ b/lib/mixlib/shellout/unix.rb @@ -194,8 +194,11 @@ module Mixlib # create a file because error pipe will auto close when we # try to create a file since it's set to CLOEXEC. if n != @process_status_pipe.last.to_i - fd = File.for_fd(n) rescue nil - fd.close if fd + begin + fd = File.for_fd(n) + fd.close if fd + rescue + end end end end -- cgit v1.2.1 From 6526c3c7ee383318747dafb2b08933aed84985f5 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 14 Jun 2013 12:12:32 -0700 Subject: add spec test for EBADF in closing fds --- spec/mixlib/shellout_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index 2020dda..131c5e1 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -1013,5 +1013,19 @@ describe Mixlib::ShellOut do end end end + + describe "#clean_parent_file_descriptors" do + # test for for_fd returning a valid File object, but close + # throwing EBADF. + it "should not throw an exception if fd.close throws EBADF" do + fd = mock('File') + fd.stub!(:close).at_least(:once).and_raise(Errno::EBADF) + File.should_receive(:for_fd).at_least(:once).and_return(fd) + shellout = Mixlib::ShellOut.new() + shellout.instance_variable_set(:@process_status_pipe, [ 98, 99 ]) + lambda { shellout.send(:clean_parent_file_descriptors) }.should_not raise_error + end + end + end end -- cgit v1.2.1