summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-26 14:00:25 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-26 14:00:25 +0000
commit4f4d7247208b467c3d48587d10761c23a41b140b (patch)
treee0490edc369285246cd561d18ec377d3606fca8e /lib
parentfbb9e6c1eb8ec1870a70b360038430d9ef1b1e08 (diff)
Make retries for Net::HTTP configurable [Feature #10674]
by stereobooster fix https://github.com/ruby/ruby/pull/1654 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index a4b919e59b..eb7d335cb5 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -670,6 +670,7 @@ module Net #:nodoc:
@open_timeout = 60
@read_timeout = 60
@continue_timeout = nil
+ @max_retries = 1
@debug_output = nil
@proxy_from_env = false
@@ -736,6 +737,21 @@ module Net #:nodoc:
# it raises a Net::ReadTimeout exception. The default value is 60 seconds.
attr_reader :read_timeout
+ # Maximum number of times to retry an idempotent request in case of
+ # Net::ReadTimeout, IOError, EOFError, Errno::ECONNRESET,
+ # Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL, Timeout::Error
+ # Should be non-negative integer number. Zero means no retries.
+ # The default value is 1.
+ def max_retries=(retries)
+ retries = retries.to_int
+ if retries < 0
+ raise ArgumentError, 'max_retries should be non-negative integer number'
+ end
+ @max_retries = retries
+ end
+
+ attr_reader :max_retries
+
# Setter for the read_timeout attribute.
def read_timeout=(sec)
@socket.read_timeout = sec if @socket
@@ -1477,7 +1493,7 @@ module Net #:nodoc:
# avoid a dependency on OpenSSL
defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
Timeout::Error => exception
- if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
+ if count < max_retries && IDEMPOTENT_METHODS_.include?(req.method)
count += 1
@socket.close if @socket
D "Conn close because of error #{exception}, and retry"