[ruby/net-http] Don't invoke response block more than once due to retry
If a socket error occurs while performing a streaming download via the response block provided to transport_request, avoid calling the response block again as this would result in duplicate data received by the client. Fixes https://github.com/ruby/net-http/pull/86 Fixes https://github.com/ruby/net-http/pull/87 Fixes [Bug #11526] https://github.com/ruby/net-http/commit/114d01b092 Co-authored-by: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
37657c79b6
commit
4d03140009
@ -2350,7 +2350,10 @@ module Net #:nodoc:
|
||||
res
|
||||
}
|
||||
res.reading_body(@socket, req.response_body_permitted?) {
|
||||
yield res if block_given?
|
||||
if block_given?
|
||||
count = max_retries # Don't restart in the middle of a download
|
||||
yield res
|
||||
end
|
||||
}
|
||||
rescue Net::OpenTimeout
|
||||
raise
|
||||
|
@ -1234,6 +1234,16 @@ class TestNetHTTPKeepAlive < Test::Unit::TestCase
|
||||
}
|
||||
end
|
||||
|
||||
def test_http_retry_failed_with_block
|
||||
start {|http|
|
||||
http.max_retries = 10
|
||||
called = 0
|
||||
assert_raise(Errno::ECONNRESET){ http.get('/'){called += 1; raise Errno::ECONNRESET} }
|
||||
assert_equal 1, called
|
||||
}
|
||||
@log_tester = nil
|
||||
end
|
||||
|
||||
def test_keep_alive_server_close
|
||||
def @server.run(sock)
|
||||
sock.close
|
||||
|
Loading…
x
Reference in New Issue
Block a user