Skip to content
Browse files

Retry a request upon a ETIMEDOUT error

Added Errno::ETIMEDOUT as an exception which will trigger a retry of the
request.

SystemCallError is not rescued as exceptions in the block execution may
raise non-socket system call errors which could erroneously trigger a
retry or incorrect exception.

Fixes #36
  • Loading branch information...
1 parent 24c70e0 commit b772eb96402f5b59d2d75d14e7f40b3e40de8fed @drbrain committed
Showing with 21 additions and 2 deletions.
  1. +7 −0 History.txt
  2. +2 −2 lib/net/http/persistent.rb
  3. +12 −0 test/test_net_http_persistent.rb
View
7 History.txt
@@ -1,3 +1,10 @@
+=== 2.8.1
+
+* Bug fixes
+ * Explain the proper way of sending parameters depending upon the request
+ method. Issue #35 by André Arko.
+ * Handle Errno::ETIMEDOUT by retrying the request. Issue #36 by André Arko.
+
=== 2.8 / 2012-10-17
* Minor enhancements
View
4 lib/net/http/persistent.rb
@@ -185,7 +185,7 @@ class Net::HTTP::Persistent
##
# The version of Net::HTTP::Persistent you are using
- VERSION = '2.8'
+ VERSION = '2.8.1'
##
# Error class for errors raised by Net::HTTP::Persistent. Various
@@ -957,7 +957,7 @@ def request uri, req = nil, &block
retry
rescue IOError, EOFError, Timeout::Error,
Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE,
- Errno::EINVAL, OpenSSL::SSL::SSLError => e
+ Errno::EINVAL, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError => e
request_failed e, req, connection if retried or not can_retry? req
View
12 test/test_net_http_persistent.rb
@@ -888,6 +888,18 @@ def test_request
assert_equal 1, reqs[c.object_id]
end
+ def test_request_ETIMEDOUT
+ c = basic_connection
+ def c.request(*a) raise Errno::ETIMEDOUT, "timed out" end
+
+ e = assert_raises Net::HTTP::Persistent::Error do
+ @http.request @uri
+ end
+
+ assert_equal 0, reqs[c.object_id]
+ assert_match %r%too many connection resets%, e.message
+ end
+
def test_request_bad_response
c = basic_connection
def c.request(*a) raise Net::HTTPBadResponse end

0 comments on commit b772eb9

Please sign in to comment.
Something went wrong with that request. Please try again.