Skip to content

Commit

Permalink
NetHttpPersistent: ConnectionError on OpenTimeout
Browse files Browse the repository at this point in the history
  - open timeout is treated as a failure to connect
  - 4.0.0 and up supports this
  • Loading branch information
olleolleolle committed May 5, 2020
1 parent 87ecaf9 commit 6a90ae5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -23,7 +23,7 @@ group :test, :development do
gem 'excon', '>= 0.27.4'
gem 'httpclient', '>= 2.2'
gem 'multipart-parser'
gem 'net-http-persistent'
gem 'net-http-persistent', '~> 4.0'
gem 'patron', '>= 0.4.2', platforms: :ruby
gem 'rack', '< 2.1'
gem 'rack-test', '>= 0.6', require: 'rack/test'
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/adapter/net_http_persistent.rb
Expand Up @@ -53,6 +53,8 @@ def perform_request(http, env)
http.request env[:url], create_request(env)
rescue Errno::ETIMEDOUT => e
raise Faraday::TimeoutError, e
rescue Net::OpenTimeout => e
raise Faraday::ConnectionFailed, e
rescue Net::HTTP::Persistent::Error => e
raise Faraday::TimeoutError, e if e.message.include? 'Timeout'

Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_examples/request_method.rb
Expand Up @@ -99,7 +99,7 @@
it 'supports timeout option' do
conn_options[:request] = { timeout: 1 }
request_stub.to_timeout
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
exc = ['NetHttp', 'NetHttpPersistent'].include?(adapter) ? Faraday::ConnectionFailed : Faraday::TimeoutError
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
end

Expand All @@ -108,7 +108,7 @@
it 'supports open_timeout option' do
conn_options[:request] = { open_timeout: 1 }
request_stub.to_timeout
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
exc = ['NetHttp', 'NetHttpPersistent'].include?(adapter) ? Faraday::ConnectionFailed : Faraday::TimeoutError
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
end

Expand Down

0 comments on commit 6a90ae5

Please sign in to comment.