summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 04:51:37 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 04:51:37 +0000
commit8a7da58c0fe28af09ce0631d6ada79e47cc7b98f (patch)
treeb555bd3f1c10aa26ad529cfa9c4655ffc1f0ed94 /lib/net
parent1c85a648febde2176493b26130b08c742b3de305 (diff)
* lib/net/http.rb: Retry HTTP requests for additional network errors.
Introduce OpenTimeout subclass of Timeout::Error. [Bug #6001] * test/net/http/test_http.rb: Reduce timeout to 0.01s for faster test * test/net/http/test_https.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/http.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 46a7902363..d6182d9052 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -360,6 +360,9 @@ module Net #:nodoc:
#
class HTTP < Protocol
+ class OpenTimeout < Timeout::Error
+ end
+
# :stopdoc:
Revision = %q$Revision$.split[1]
HTTPVersion = '1.1'
@@ -788,7 +791,9 @@ module Net #:nodoc:
def connect
D "opening connection to #{conn_address()}..."
- s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
+ s = timeout(@open_timeout, OpenTimeout) {
+ TCPSocket.open(conn_address(), conn_port())
+ }
D "opened"
if use_ssl?
ssl_parameters = Hash.new
@@ -824,7 +829,7 @@ module Net #:nodoc:
end
# Server Name Indication (SNI) RFC 3546
s.hostname = @address if s.respond_to? :hostname=
- timeout(@open_timeout) { s.connect }
+ timeout(@open_timeout, OpenTimeout) { s.connect }
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
s.post_connection_check(@address)
end
@@ -1355,9 +1360,11 @@ module Net #:nodoc:
}
res
}
- end_transport req, res
- res
- rescue EOFError, Errno::ECONNRESET => exception
+ rescue IOError, EOFError,
+ Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
+ OpenSSL::SSL::SSLError, Timeout::Error => exception
+ raise if OpenTimeout === exception
+
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
count += 1
@socket.close if @socket and not @socket.closed?
@@ -1367,11 +1374,14 @@ module Net #:nodoc:
D "Conn close because of error #{exception}"
@socket.close if @socket and not @socket.closed?
raise
- rescue => exception
- D "Conn close because of error #{exception}"
- @socket.close if @socket and not @socket.closed?
- raise exception
end
+
+ end_transport req, res
+ res
+ rescue => exception
+ D "Conn close because of error #{exception}"
+ @socket.close if @socket and not @socket.closed?
+ raise exception
end
def begin_transport(req)