Class: Tempfile

Inherits:
Object show all
Defined in:
lib/chef/monkey_patches/tempfile.rb

Overview

Tempfile (Patch)

Tempfile has a horrible bug where it causes an IOError: closed stream in its finalizer, leading to intermittent application crashes with confusing stack traces. Here we monkey patch the fix into place. You can track the bug on ruby's redmine: redmine.ruby-lang.org/issues/show/3119

The patch is slightly different for Ruby 1.8 and Ruby 1.9, both patches are included here.

Instance Method Summary collapse

Instance Method Details



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chef/monkey_patches/tempfile.rb', line 31

def unlink
  # keep this order for thread safeness
  begin
    File.unlink(@tmpname) if File.exist?(@tmpname)
    @@cleanlist.delete(@tmpname)
    @tmpname = nil
    ObjectSpace.undefine_finalizer(self)
  rescue Errno::EACCES
    # may not be able to unlink on Windows; just ignore
  end
end