summaryrefslogtreecommitdiff
path: root/lib/mixlib/shellout/unix.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2014-03-06 10:49:07 -0800
committerdanielsdeleo <dan@opscode.com>2014-03-07 12:19:21 -0800
commit0397bbd953a1fcd05a26fde120e7710ac7fd6862 (patch)
treef75ee6f6f8e972784789ddb627e8019e9f63bb86 /lib/mixlib/shellout/unix.rb
parentcbb4de9fd775342b307deef997f9e08aa9f54cd8 (diff)
downloadmixlib-shellout-0397bbd953a1fcd05a26fde120e7710ac7fd6862.tar.gz
Retire the GC disable hack for all but ruby 1.8.7
Originally we needed this hack for 1.8.6 and 1.8.7, which were the most common versions in use at the time. 1.8.6 is dead so we don't need to account for it any more, which leaves 1.8.7 as the only case we need to care about for this hack. On Ruby 1.9 and greater this hack isn't needed and causes memory bloat for very long running shell commands.
Diffstat (limited to 'lib/mixlib/shellout/unix.rb')
-rw-r--r--lib/mixlib/shellout/unix.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index a2518cf..e8aa26e 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -20,6 +20,11 @@ module Mixlib
class ShellOut
module Unix
+ # "1.8.7" as a frozen string. We use this with a hack that disables GC to
+ # avoid segfaults on Ruby 1.8.7, so we need to allocate the fewest
+ # objects we possibly can.
+ ONE_DOT_EIGHT_DOT_SEVEN = "1.8.7".freeze
+
# Option validation that is unix specific
def validate_options(opts)
# No options to validate, raise exceptions here if needed
@@ -50,10 +55,10 @@ module Mixlib
configure_parent_process_file_descriptors
# Ruby 1.8.7 and 1.8.6 from mid 2009 try to allocate objects during GC
- # when calling IO.select and IO#read. Some OS Vendors are not interested
- # in updating their ruby packages (Apple, *cough*) and we *have to*
- # make it work. So I give you this epic hack:
- GC.disable
+ # when calling IO.select and IO#read. Disabling GC works around the
+ # segfault, but obviously it's a bad workaround. We no longer support
+ # 1.8.6 so we only need this hack for 1.8.7.
+ GC.disable if RUBY_VERSION == ONE_DOT_EIGHT_DOT_SEVEN
# CHEF-3390: Marshall.load on Ruby < 1.8.7p369 also has a GC bug related
# to Marshall.load, so try disabling GC first.