Skip to content

Commit

Permalink
Don't invoke response block more than once due to retry
Browse files Browse the repository at this point in the history
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 #86
Fixes #87 

Fixes [Bug #11526]

Co-authored-by: Jeremy Stanley <jeremy@instructure.com>
  • Loading branch information
jeremyevans and jstanley0 authored Jan 5, 2024
1 parent 21e226c commit 114d01b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,10 @@ def transport_request(req)
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
Expand Down
10 changes: 10 additions & 0 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,16 @@ def test_http_retry_failed
}
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
Expand Down

0 comments on commit 114d01b

Please sign in to comment.