[前][次][番号順一覧][スレッド一覧]

ruby-changes:14698

From: nobu <ko1@a...>
Date: Wed, 3 Feb 2010 21:15:17 +0900 (JST)
Subject: [ruby-changes:14698] Ruby:r26553 (ruby_1_8): * lib/net/http.rb (Net::HTTP#request): close @socket only after

nobu	2010-02-03 21:15:02 +0900 (Wed, 03 Feb 2010)

  New Revision: 26553

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26553

  Log:
    * lib/net/http.rb (Net::HTTP#request): close @socket only after
      started.  [ruby-core:28028]

  Added files:
    branches/ruby_1_8/test/net/http/test_connection.rb
  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/net/http.rb

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 26552)
+++ ruby_1_8/ChangeLog	(revision 26553)
@@ -1,3 +1,8 @@
+Wed Feb  3 21:14:59 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/net/http.rb (Net::HTTP#request): close @socket only after
+	  started.  [ruby-core:28028]
+
 Mon Feb  1 16:43:09 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval.c (proc_invoke): reverted r25975.  [ruby-dev:39931]
Index: ruby_1_8/lib/net/http.rb
===================================================================
--- ruby_1_8/lib/net/http.rb	(revision 26552)
+++ ruby_1_8/lib/net/http.rb	(revision 26553)
@@ -1044,7 +1044,8 @@
       end
 
       req.set_body_internal body
-      begin_transport req
+      begin
+        begin_transport req
         req.exec @socket, @curr_http_version, edit_path(req.path)
         begin
           res = HTTPResponse.read_new(@socket)
@@ -1052,13 +1053,14 @@
         res.reading_body(@socket, req.response_body_permitted?) {
           yield res if block_given?
         }
-      end_transport req, res
+        end_transport req, res
+      rescue => exception
+        D "Conn close because of error #{exception}"
+        @socket.close unless @socket.closed?
+        raise exception
+      end
 
       res
-    rescue => exception
-      D "Conn close because of error #{exception}"
-      @socket.close unless @socket.closed?
-      raise exception
     end
 
     private
Index: ruby_1_8/test/net/http/test_connection.rb
===================================================================
--- ruby_1_8/test/net/http/test_connection.rb	(revision 0)
+++ ruby_1_8/test/net/http/test_connection.rb	(revision 26553)
@@ -0,0 +1,33 @@
+require 'net/http'
+require 'test/unit'
+
+module TestHTTP
+  class HTTPConnectionTest < Test::Unit::TestCase
+    def test_connection_refused_in_request
+      bug2708 = '[ruby-core:28028]'
+      port = nil
+      localhost = "127.0.0.1"
+      t = Thread.new {
+        TCPServer.open(localhost, 0) do |serv|
+          _, port, _, _ = serv.addr
+          if clt = serv.accept
+            clt.close
+          end
+        end
+      }
+      begin
+        sleep 0.1 until port
+        assert_raise(Errno::ECONNRESET, bug2708) {
+          n = Net::HTTP.new(localhost, port)
+          n.request_get('/')
+        }
+      ensure
+        t.join if t
+      end
+      assert_raise(Errno::ECONNREFUSED, bug2708) {
+        n = Net::HTTP.new(localhost, port)
+        n.request_get('/')
+      }
+    end
+  end
+end

Property changes on: ruby_1_8/test/net/http/test_connection.rb
___________________________________________________________________
Name: svn:eol-style
   + LF


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]