faraday: Faraday::Error: false is not registered on Faraday::Adapter
Basic Info
Faraday intermittently errors on setting up middleware/adapter
- Faraday Version: 1.4.1
- Ruby Version: 2.4.0
Issue description
I have an application that uses Faraday for external calls using typhoeus adapter. Every once a while (~1% of requests) faraday connection fails to initialize with the error:
Faraday::Error: false is not registered on Faraday::Adapter
Here is how the connection is set up:
# connection_helper.rb
require 'faraday'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
require 'faraday-http-cache'
module ConnectionHelper
def connection(host)
Faraday.new(url: host) do |conn|
conn.use :http_cache, store: CACHE_STORE, shared_cache: false
conn.adapter :typhoeus
end
end
end
# foo_service.rb
class MyService
class << self
include ConnectionHelper
def get(host, path)
response = connection(host).get(path)
handle_error(response)
response.body
end
end
end
Steps to reproduce
Sorry, I cannot reproduce this error locally, but it’s painfully consistent (yet random) in cloud environments.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (8 by maintainers)
That normally means that
typhoeuswas not registered as an adapter. There can be multiple reasons for this. Faraday originally bundled and registered typhoeus itself, then as of Faraday 2.0 this is no longer the case and there’s now a standalone adapter.I’m unsure how
searchkickworks, but it’s worth checking if they support Faraday 2.0. If they don’t they might still be relying on the out-of-the-box adapter in v1.x, which won’t work in v2.0. If you’d still like to use Faraday 2.0 (which I definitely recommend) you could try adding thefaraday-typhoeusgem explicitly to your gemfile as that should be compatible with Faraday 2.0.If that doesn’t work and you still have questions, please open a separate issue as I’m now pretty sure this is unrelated to this thread 😄
@abhitrivedi @raydog153 Apparently this is a known Ruby 2.4.0 bug: https://bugs.ruby-lang.org/issues/13107
It happens when using
def_delegators(which are used in Faraday). I’ll see if there’s any fix we can apply on our side, but of course the easiest solution is to upgrade to Ruby 2.4.1 where this bug have been fixed.@iMacTia actually I misread the word false, this is my exact error that I’m getting:
Faraday::Error: :typhoeus is not registered on Faraday::AdapterI’m getting this when trying to use
SearchKickwith typhoeus per their instructions: https://github.com/ankane/searchkick#persistent-http-connectionsThey mention to only add
typhoeusto the gemfile by itself, and when I reindex the database (ie searchkick uses faraday/typheous to connect) it throws the error aboveif I add the faraday-typheous gem to the gemfile, then it works without any error, but this appears to be unexpected behavior as the owner of searchkick is confident that its not needed
https://github.com/ankane/searchkick/issues/1623