Skip to content

Commit

Permalink
Merge 6e8b1ac into 3ecd5f3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri Levenhagen committed Feb 9, 2022
2 parents 3ecd5f3 + 6e8b1ac commit 9f224a2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/http/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class StateError < ResponseError; end
# Generic Timeout error
class TimeoutError < Error; end

# Timeout when first establishing the conncetion
class ConnectTimeoutError < TimeoutError; end

# Header value is of unexpected format (similar to Net::HTTPHeaderSyntaxError)
class HeaderError < Error; end
end
2 changes: 1 addition & 1 deletion lib/http/timeout/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def reset_counter

def connect(socket_class, host, port, nodelay = false)
reset_timer
::Timeout.timeout(@time_left, TimeoutError) do
::Timeout.timeout(@time_left, ConnectTimeoutError) do
@socket = socket_class.open(host, port)
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
end
Expand Down
2 changes: 1 addition & 1 deletion lib/http/timeout/per_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(*args)
end

def connect(socket_class, host, port, nodelay = false)
::Timeout.timeout(@connect_timeout, TimeoutError) do
::Timeout.timeout(@connect_timeout, ConnectTimeoutError) do
@socket = socket_class.open(host, port)
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ def on_error(request, error)
client.use(:test_feature => feature_instance).
timeout(0.001).
request(:post, sleep_url)
end.to raise_error(HTTP::TimeoutError)
expect(feature_instance.captured_error).to be_a(HTTP::TimeoutError)
end.to raise_error(HTTP::ConnectTimeoutError)
expect(feature_instance.captured_error).to be_a(HTTP::ConnectTimeoutError)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/http_handling_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
sleep 1.25
end

expect { response }.to raise_error(HTTP::TimeoutError, /execution/)
expect { response }.to raise_error(HTTP::ConnectTimeoutError, /execution/)
end

it "errors if reading takes too long" do
Expand Down

0 comments on commit 9f224a2

Please sign in to comment.