Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge revision(s) 26553:

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


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@27955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 36db90bdaa60326742a1ec62b80636356cbc613a 1 parent b08117e
@shyouhei shyouhei authored
View
5 ChangeLog
@@ -1,3 +1,8 @@
+Sat May 22 19:46:27 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/net/http.rb (Net::HTTP#request): close @socket only after
+ started. [ruby-core:28028]
+
Sat May 22 19:36:38 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (proc_invoke): reverted r25975. [ruby-dev:39931]
View
14 lib/net/http.rb
@@ -1044,7 +1044,8 @@ def request(req, body = nil, &block) # :yield: +response+
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 @@ def request(req, body = nil, &block) # :yield: +response+
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
View
33 test/net/http/test_connection.rb
@@ -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
View
2  version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2010-05-22"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20100522
-#define RUBY_PATCHLEVEL 260
+#define RUBY_PATCHLEVEL 261
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
Please sign in to comment.
Something went wrong with that request. Please try again.