Permalink
Browse files

Handled IOError in pipeline_check for pipelining on a closed socket

  • Loading branch information...
1 parent 22005b9 commit c70da58fe6f9b2e62fe17e0ed918ce8b39612d94 @drbrain committed Apr 13, 2012
Showing with 43 additions and 4 deletions.
  1. +6 −0 History.txt
  2. +1 −1 lib/net/http/pipeline.rb
  3. +36 −3 test/test_net_http_pipeline.rb
View
6 History.txt
@@ -1,3 +1,9 @@
+=== 1.0.1 / 2012-04-13
+
+* Bug fixes
+ * IOError is now handled in pipeline_check in case you pipeline to a closed
+ socket.
+
=== 1.0 / 2011-03-29
* API change
View
2 lib/net/http/pipeline.rb
@@ -223,7 +223,7 @@ def pipeline_check requests, responses
begin
res = request req
rescue Timeout::Error, EOFError, Errno::ECONNABORTED, Errno::ECONNRESET,
- Errno::EPIPE, Net::HTTPBadResponse => e
+ Errno::EPIPE, Net::HTTPBadResponse, IOError => e
if retried then
requests.unshift req
raise ResponseError.new(e, requests, responses)
View
39 test/test_net_http_pipeline.rb
@@ -14,6 +14,17 @@ def setup
@get2 = Net::HTTP::Get.new '/'
@get3 = Net::HTTP::Get.new '/'
@post = Net::HTTP::Post.new '/'
+
+ remove_start
+
+ def start
+ end
+ end
+
+ def remove_start
+ class << self
+ alias_method :old_start, :start if method_defined? :start
+ end
end
##
@@ -147,9 +158,6 @@ def r.header() @header end
r
end
- def start
- end
-
def started?() @started end
# tests start
@@ -273,6 +281,8 @@ def test_pipeline_retry
@socket = @error_socket
+ remove_start
+
def start
@socket = @good_socket
end
@@ -337,6 +347,8 @@ def test_pipeline_retry_fail_different
@sockets = [@error_socket2, @good_socket]
+ remove_start
+
def start
@socket = @sockets.shift
end
@@ -378,6 +390,8 @@ def test_pipeline_retry_fail_same
@socket = @error_socket
+ remove_start
+
def start
@socket = @error_socket2
end
@@ -446,6 +460,8 @@ def test_pipeline_check_bad_response
@socket2.read_io.write http_response('Worked 1!')
@socket2.start
+ remove_start
+
def start
@socket = @socket2
end
@@ -481,6 +497,23 @@ def test_pipeline_check_http_1_0
refute pipelining
end
+ def test_pipeline_check_ioerror
+ @socket = Buffer.new IOError, true
+ @socket.read_io.write http_response('Worked 1!')
+ @socket.start
+
+ requests = [@get1, @get2]
+ responses = []
+
+ assert_raises Net::HTTP::Pipeline::ResponseError do
+ pipeline_check requests, responses
+ end
+
+ assert_equal [@get1, @get2], requests
+ assert_equal 0, responses.length
+ refute pipelining
+ end
+
def test_pipeline_check_non_persistent
@socket = Buffer.new
@socket.read_io.write http_response('Worked 1!', 'Connection: close')

0 comments on commit c70da58

Please sign in to comment.