Skip to content

don't invoke response block more than once due to retry #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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