[#39222] [Bug #2036] AIX 5L 5.2にて、ruby-1.8.7-p174のビルド時にmake testをするとエラーになった。not ok float 7 -- ./sample/test.rb:1232 — 和弥 寺元 <redmine@...>

Bug #2036: AIX 5L 5.2にて、ruby-1.8.7-p174のビルド時にmake testをするとエラーになった。not ok float 7 -- ./sample/test.rb:1232

13 messages 2009/09/03

[#39249] [Bug #2060] DLをCからRubyに変換する事を勧めます — Aaron Patterson <redmine@...>

Bug #2060: DLをCからRubyに変換する事を勧めます

10 messages 2009/09/07

[#39282] [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — takeru sasaki <redmine@...>

チケット #2067 が更新されました。 (by takeru sasaki)

15 messages 2009/09/10
[#39283] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39284] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Nobuyoshi Nakada <nobu@...> 2009/09/10

なかだです。

[#39297] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39298] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Tanaka Akira <akr@...> 2009/09/10

In article <E1MliJq-0000yc-4o@x61.netlab.jp>,

[#39302] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — takeru sasaki <sasaki.takeru@...> 2009/09/10

言いだしっぺの佐々木です。

[#39307] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39345] [Bug #2111] Error:test_rm_f(TestFileUtils) — Kazuhiro NISHIYAMA <redmine@...>

Bug #2111: Error:test_rm_f(TestFileUtils)

11 messages 2009/09/17

[#39352] [ruby19] Thread 切替えが異常に遅い? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

12 messages 2009/09/20

[#39367] Almost endless loop of BigMath::atan(x) when x.abs >= 1 — "Masahiro Kanai (CanI)" <cani.m.61st@...>

金井 仁弘と申します。

13 messages 2009/09/23
[#39980] Re: Almost endless loop of BigMath::atan(x) when x.abs >= 1 — TOYOFUKU Chikanobu <nobu_toyofuku@...> 2010/01/07

豊福です。遅い反応ですが。

[#39982] Re: Almost endless loop of BigMath::atan(x) when x.abs >= 1 — TOYOFUKU Chikanobu <nobu_toyofuku@...> 2010/01/07

豊福です。

[#39388] Re: [ruby-cvs:32331] Ruby:r25113 (trunk): String#inspect's encoding should be fixed. — "Martin J. Dürst" <duerst@...>

成瀬さん、こんにちは。

9 messages 2009/09/28

[ruby-dev:39284] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている

From: Nobuyoshi Nakada <nobu@...>
Date: 2009-09-10 05:18:51 UTC
List: ruby-dev #39284
なかだです。

At Thu, 10 Sep 2009 13:17:04 +0900,
Yukihiro Matsumoto wrote in [ruby-dev:39283]:
> |begin
> |  open(url) do |f|
> |    ...
> |  end
> |rescue OpenURI::HTTPError => e
> |  e.io.close
> |end
> |とすれば良いのですね。
> 
> いや、そんなことしなければいけないのはやっぱりおかしいと思い
> ますよ。なんでかな。

エラーページの内容も例外の情報の一部になっているので、Tempfileを
使っている場合には当然そうなるでしょう。

エラーページの内容は捨ててしまうか、エラーのときにはサイズに関わ
らずStringIOにするか、Tempfileなので気にしないことにするか。


Index: lib/open-uri.rb
===================================================================
--- lib/open-uri.rb	(revision 24824)
+++ lib/open-uri.rb	(working copy)
@@ -211,5 +211,6 @@ module OpenURI
         end
         if !options.fetch(:redirect, true)
-          raise HTTPRedirect.new(buf.io.status.join(' '), buf.io, redirect)
+          buf.io.close
+          raise HTTPRedirect.new(buf.io.status.join(' '), redirect)
         end
         unless OpenURI.redirectable?(uri, redirect)
@@ -340,16 +341,18 @@ module OpenURI
         loc_uri = URI.parse(resp['location'])
       rescue URI::InvalidURIError
-        raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io)
+        io.close
+        raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)')
       end
       throw :open_uri_redirect, loc_uri
     else
-      raise OpenURI::HTTPError.new(io.status.join(' '), io)
+      io.close
+      raise OpenURI::HTTPError.new(io.status.join(' '))
     end
   end
 
   class HTTPError < StandardError
-    def initialize(message, io)
+    def initialize(message)
       super(message)
-      @io = io
+      @io = nil
     end
     attr_reader :io
@@ -357,6 +360,6 @@ module OpenURI
 
   class HTTPRedirect < HTTPError
-    def initialize(message, io, uri)
-      super(message, io)
+    def initialize(message, uri)
+      super(message)
       @uri = uri
     end

Index: lib/open-uri.rb
===================================================================
--- lib/open-uri.rb	(revision 24824)
+++ lib/open-uri.rb	(working copy)
@@ -150,5 +150,5 @@ module OpenURI
         yield io
       ensure
-        io.close
+        io.close unless io.closed?
       end
     else
@@ -200,5 +200,5 @@ module OpenURI
     while true
       redirect = catch(:open_uri_redirect) {
-        buf = Buffer.new
+        buf = Buffer.new(options)
         uri.buffer_open(buf, find_proxy.call(uri), options)
         nil
@@ -312,5 +312,8 @@ module OpenURI
       http.request(req) {|response|
         resp = response
-        if options[:content_length_proc] && Net::HTTPSuccess === resp
+        unless success = Net::HTTPSuccess === resp
+          buf.unlimit
+        end
+        if options[:content_length_proc] && success
           if resp.key?('Content-Length')
             options[:content_length_proc].call(resp['Content-Length'].to_i)
@@ -321,5 +324,5 @@ module OpenURI
         resp.read_body {|str|
           buf << str
-          if options[:progress_proc] && Net::HTTPSuccess === resp
+          if options[:progress_proc] && success
             options[:progress_proc].call(buf.size)
           end
@@ -365,7 +368,10 @@ module OpenURI
 
   class Buffer # :nodoc:
-    def initialize
+    def initialize(options)
       @io = StringIO.new
       @size = 0
+      if @stringmax = options.fetch(:max_stringio_size, StringMax)
+        raise ArgumentError, "negative max_stringio_size" if @stringmax < 0
+      end
     end
     attr_reader :size
@@ -375,5 +381,5 @@ module OpenURI
       @io << str
       @size += str.length
-      if StringIO === @io && StringMax < @size
+      if @stringmax && @stringmax < @size
         require 'tempfile'
         io = Tempfile.new('open-uri')
@@ -382,7 +388,12 @@ module OpenURI
         io << @io.string
         @io = io
+        @stringmax = nil
       end
     end
 
+    def unlimit
+      @stringmax = nil
+    end
+
     def io
       Meta.init @io unless Meta === @io


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread