From: Niels Ganser <niels@herimedia.com>
To: rack-devel@googlegroups.com
Subject: Tempfile#unlink changes in Ruby 1.9.1-p152
Date: Sat, 18 Jul 2009 21:33:24 +0200 [thread overview]
Message-ID: <be683e140907181233s3a84dbacpdc94d1989c2c4e77@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1201 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 1408 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 191-152-unlink-workaround.patch --]
[-- Type: text/x-diff, Size: 1093 bytes --]
From d960563139192baf39a380055fce85ed5ecde465 Mon Sep 17 00:00:00 2001
From: Niels Ganser <niels@herimedia.com>
Date: Sat, 18 Jul 2009 21:14:21 +0200
Subject: [PATCH] Workaround for Tempfile#unlink change in 1.9.1-p152
Starting with patchlevel 152, Ruby 1.9 closes a Tempfile
upon unlinking it. In such cases we would run into IOErrors
(closed stream) when trying to keep using @rewindable_io
after unlinking it.
---
lib/rack/rewindable_input.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/rack/rewindable_input.rb b/lib/rack/rewindable_input.rb
index accd96b..b4d1952 100644
--- a/lib/rack/rewindable_input.rb
+++ b/lib/rack/rewindable_input.rb
@@ -74,7 +74,7 @@ module Rack
@rewindable_io.chmod(0000)
@rewindable_io.set_encoding(Encoding::BINARY) if @rewindable_io.respond_to?(:set_encoding)
@rewindable_io.binmode
- if filesystem_has_posix_semantics?
+ if filesystem_has_posix_semantics? && "#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}" < "1.9.1.152"
@rewindable_io.unlink
@unlinked = true
end
--
1.6.0.4
next reply other threads:[~2009-07-18 19:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-18 19:33 Niels Ganser [this message]
2009-07-18 22:25 ` Tempfile#unlink changes in Ruby 1.9.1-p152 Eric Wong
2009-07-18 23:43 ` Niels Ganser
2009-07-22 7:53 ` Hongli Lai
2009-07-22 14:41 ` Niels Ganser
2009-08-08 5:49 ` Taylor luk
2009-08-12 5:13 ` Taylor luk
2009-08-17 17:27 ` Hongli Lai
2009-08-20 19:05 ` Hongli Lai
2009-08-20 21:26 ` Jeremy Kemper
2009-08-21 0:23 ` masayoshi takahashi
2009-08-21 9:09 ` Hongli Lai
2009-08-25 15:32 ` Hongli Lai
2009-08-26 8:10 ` Hongli Lai
2009-09-02 18:52 ` Niels
2009-08-15 19:47 ` Ryan Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://groups.google.com/group/rack-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be683e140907181233s3a84dbacpdc94d1989c2c4e77@mail.gmail.com \
--to=rack-devel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).