Hey everyone,

after updating my Ruby installation recently, I constantly ran into IOErrors when using rack. After a bit of digging around I could narrow this down to RewindableInput#make_rewindable, more specifically lib/rack/rewindable_input.rb:78. After unlinking the tempfile, the IO object was closed and thus e.g. the @rewindable_io.rewind in line 93 wasn't possible any more.

I could trace this back to a change in Ruby introduced in revisions 23494 (trunk) and 23537 (branches/ruby_1_9_1). The relevant changes are reproduced in ruby-core[1] and redmine[2]. As you can see, Tempfile#unlink now calls #close before actually unlinking the file.

An obvious workaround is attached but surely the whole "if filesystem_has_posix_semantics?" block should be reworked or this should be followed up with the ruby core guys. While I'm not exactly sure whether we can consider closing the IO stream to a file before unlinking it a bug in itself, Tempfile#unlink now sure is inconsistent with File#unlink. Principle of least surprise? No, Sir!

What do you guys think?

Best,
Niels

[1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23505
[2] http://redmine.ruby-lang.org/issues/show/1494