Skip to content
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
2 changes: 1 addition & 1 deletion async-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "async-pool", "~> 0.11"
spec.add_dependency "io-endpoint", "~> 0.14"
spec.add_dependency "io-stream", "~> 0.14"
spec.add_dependency "protocol-http", "~> 0.64"
spec.add_dependency "protocol-http", "~> 0.66"
spec.add_dependency "protocol-http1", "~> 0.39"
spec.add_dependency "protocol-http2", "~> 0.26"
spec.add_dependency "protocol-url", "~> 0.2"
Expand Down
3 changes: 2 additions & 1 deletion lib/async/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "async/pool/controller"

require "protocol/http/body/completable"
require "protocol/http/error"
require "protocol/http/methods"

require_relative "protocol"
Expand Down Expand Up @@ -126,7 +127,7 @@ def call(request)
else
raise
end
rescue SocketError, IOError, EOFError, Errno::ECONNRESET, Errno::EPIPE
rescue ::Protocol::HTTP::RemoteError, SocketError, IOError, EOFError, Errno::ECONNRESET, Errno::EPIPE
if connection
@pool.release(connection)
connection = nil
Expand Down
6 changes: 6 additions & 0 deletions lib/async/http/protocol/http2/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def wait
if @exception
raise @exception
end
rescue ::Protocol::HTTP2::StreamError => error
if error.code == ::Protocol::HTTP2::Error::INTERNAL_ERROR
raise ::Protocol::HTTP::RemoteError, error.message
end

raise
end

# Called when the stream is closed.
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Retry safe requests when a remote HTTP/2 endpoint resets the stream with `INTERNAL_ERROR` before returning a response.

## v0.98.1

- Probe idle HTTP/1 connections before reuse, avoiding requests on connections already closed by the peer.
Expand Down
21 changes: 21 additions & 0 deletions test/async/http/client/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ def make_response(request, connection, attempt)
expect(client.chunks).to be == ["Hello", "Hello"]
end

it "rewinds idempotent request bodies after remote failures" do
client = RetryClient.new([Protocol::HTTP::RemoteError.new("Remote endpoint failed.")])
request = Protocol::HTTP::Request["PUT", "/", {}, ["Hello"]]

response = client.call(request)

expect(response).to be(:success?)
expect(client.chunks).to be == ["Hello", "Hello"]
end

it "does not retry non-idempotent requests after remote failures" do
client = RetryClient.new([Protocol::HTTP::RemoteError.new("Remote endpoint failed.")])
request = Protocol::HTTP::Request["POST", "/", {}, ["Hello"]]

expect do
client.call(request)
end.to raise_exception(Protocol::HTTP::RemoteError)

expect(client.chunks).to be == ["Hello"]
end

it "rewinds non-idempotent request bodies after refused requests" do
client = RetryClient.new([Protocol::HTTP::RefusedError.new("Request not processed.")])
request = Protocol::HTTP::Request["POST", "/", {}, ["Hello"]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@
end.wait
end

it "maps a remote internal error while waiting for headers" do
Async do |task|
client_connection = Async::HTTP::Protocol::HTTP2::Client.new(client_stream)
client_connection.open!

response = client_connection.create_response
response.stream.close!(Protocol::HTTP2::INTERNAL_ERROR)

expect do
client_connection.read_response(response)
end.to raise_exception(Protocol::HTTP::RemoteError).and(
have_attributes(
cause: be_a(Protocol::HTTP2::StreamError).and(
have_attributes(code: be == Protocol::HTTP2::INTERNAL_ERROR)
)
)
)
end.wait
end

it "does not raise error when connection closes without active streams" do
Async do |task|
# Create client connection
Expand Down
Loading