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!
> 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.
A part of me died when I read that.
> 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?
Thanks for the heads up, I just posted my thoughts on Redmine about this. Hopefully the Ruby team is willing to fix it.
If we have to go this route, what about just explicitly unlinking it? I'm not going to go as far as undefining the finalizer that Tempfile defines since the finalizer checks if the file exists before unlinking anyways.
diff --git a/lib/rack/rewindable_input.rb b/lib/rack/rewindable_input.rb index accd96b..fcd6d06 100644 --- a/lib/rack/rewindable_input.rb +++ b/lib/rack/rewindable_input.rb @@ -75,7 +75,7 @@ module Rack @rewindable_io.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding) @rewindable_io.binmode if filesystem_has_posix_semantics? - @rewindable_io.unlink + File.unlink(@rewindable_io.path) @unlinked = true end
> If we have to go this route, what about just explicitly unlinking it? > I'm not going to go as far as undefining the finalizer that Tempfile > defines since the finalizer checks if the file exists before unlinking > anyways.
I don't think any change in the rack codebase will be necessary as I fully expect this to be fixed in Ruby before the next release. Considering that many people are even still using 1.8 I don't think too many compile from trunk or any other svn branch for that matter. Those who do would probably check the list here when in trouble, no?
Presumably so. I'll wait until the weekend to see if there's activity on the bug report [1] and, if there isn't any, then bring this to the attention of ruby-core to see what can be done.
> Presumably so. I'll wait until the weekend to see if there's activity
> on the bug report [1] and, if there isn't any, then bring this to the
> attention of ruby-core to see what can be done.
I think this is not getting enough attention as it deserves, The issue
isn't about people using svn trunk release of ruby, But Ruby 1.9.1-
p243 which is the latest stable version of ruby people can download
from http://ruby-lang.org
Passenger issue tracker have marked this issue invalid in their bug
tracker,I have tried patch described in the links above and no
success.
Tempfile class is been patched in Rack. Perphas the upcoming 1.0.1
release, Anyone who can provide some status update or point me to the
right direction ?
Cheers..
Taylor Luk
On Aug 8, 3:49 pm, Taylor luk <subject...@gmail.com> wrote:
> I have the same problem with Ruby 1.9 + Passenger,
> Is there any chance that the workaround provided above will be
> included in the coming 1.0.1 release ?
> On Jul 23, 12:41 am, Niels Ganser <ni...@herimedia.com> wrote:
> > Presumably so. I'll wait until the weekend to see if there's activity
> > on the bug report [1] and, if there isn't any, then bring this to the
> > attention of ruby-core to see what can be done.
I just wanted to add: after reading that I decided to grab the latest
stable ruby from svn. I'm way over my head with this stuff, but after
successfully installing ruby and attempting to use Passenger, it
continued to fail with this same error. I also cloned the bleeding-
edge rack overwriting my rack gem (I didn't know if that would work or
not, but I know rack is a dependency of Rails so I did'nt know how
else to do it...) with no luck. I did have some trouble with that
version of Ruby and sqlite3-ruby, so I've reverted back to 1.9.1-p243
Ryan
On Jul 18, 6:43 pm, Niels Ganser <ni...@herimedia.com> wrote:
> > If we have to go this route, what about just explicitly unlinking it?
> > I'm not going to go as far as undefining the finalizer that Tempfile
> > defines since the finalizer checks if the file exists before unlinking
> > anyways.
> I don't think any change in the rack codebase will be necessary as I
> fully expect this to be fixed in Ruby before the next release.
> Considering that many people are even still using 1.8 I don't think
> too many compile from trunk or any other svn branch for that matter.
> Those who do would probably check the list here when in trouble, no?
On Aug 12, 7:13 am, Taylor luk <subject...@gmail.com> wrote:
> Hi guys,
> I think this is not getting enough attention as it deserves, The issue
> isn't about people using svn trunk release of ruby, But Ruby 1.9.1-
> p243 which is the latest stable version of ruby people can download
> fromhttp://ruby-lang.org
> Passenger issue tracker have marked this issue invalid in their bug
> tracker,I have tried patch described in the links above and no
> success.
> Tempfile class is been patched in Rack. Perphas the upcoming 1.0.1
> release, Anyone who can provide some status update or point me to the
> right direction ?
Well I want to have this issue solved, it's just that right now I'm
buried under tons of client work so I haven't had the time yet.
On Aug 21, 2:23 am, masayoshi takahashi <takahash...@gmail.com> wrote:
> Hi,
> 2009/8/21 Jeremy Kemper <jer...@bitsweat.net>:
> > How about heavily advocating for upstream to accept the fix?
> > Perhaps they didn't get the message. Try another post to ruby-core.
> I agree with Jeremy (I don't understand the problem except Rack has trouble
> because of r23494, but Matz also doesn't seem to know the problem.)