algoliasearch-client-ruby icon indicating copy to clipboard operation
algoliasearch-client-ruby copied to clipboard

Version 2.3.0 causing "Algolia::AlgoliaUnreachableHostError: Unreachable hosts"

Open paulspringett opened this issue 3 years ago • 4 comments

  • Algolia Client Version: 2.3.0
  • Language Version: Ruby 2.7.4

Description

Upgrading to version 2.3.0 causes the following error when trying to connect to Algolia:

Algolia::AlgoliaUnreachableHostError: Unreachable hosts

These warnings have also started appearing in console output:

Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!

/Users/paul/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-net_http-2.1.0/lib/faraday/adapter/net_http.rb:36: warning: already initialized constant Faraday::Adapter::NetHttp::NET_HTTP_EXCEPTIONS
/Users/paul/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-0.17.5/lib/faraday/adapter/net_http.rb:12: warning: previous definition of NET_HTTP_EXCEPTIONS was here

Steps To Reproduce

  1. Install Algolia 2.3.0
  2. Configure an Algolia client with a valid app ID, admin API key and index name
  3. Call #set_settings, for example

Issue does not occur on version 2.2.2

I suspect it was this PR that introduced the issue? https://github.com/algolia/algoliasearch-client-ruby/pull/471/files

paulspringett avatar Oct 05 '22 12:10 paulspringett

Hi @paulspringett !

Thank you for reporting this issue, and sorry to hear you're running into this.

I tried to replicate the issue, but everything seems to work fine on my side. Would it be possible for you to give us a minimal repository in which there's a setup that replicates this issue, please? Without it, we won't be able to look into this behavior since I'm not able to reproduce this issue on my side with the steps you provided.

Thank you in advance! 😄

DevinCodes avatar Oct 07 '22 07:10 DevinCodes

Hey @DevinCodes thanks so much for the quick response!

I think I've tracked it down to an older version of Faraday that we're using within our app:

# algolia_faraday_test.rb
require "bundler/inline"

gemfile do
  source "https://rubygems.org"

  ruby "3.1.0"
  gem "faraday", "0.17.4"
  gem "algolia", "2.3.0"
end

search_config = Algolia::Search::Config.new(
  application_id: ENV.fetch("ALGOLIA_APPLICATION_ID"),
  api_key: ENV.fetch("ALGOLIA_ADMIN_API_KEY")
)

client = Algolia::Search::Client.create_with_config(search_config)
index = client.init_index(ENV.fetch("ALGOLIA_INDEX_NAME"))

puts index.get_settings
$ ALGOLIA_APPLICATION_ID=2GR****** ALGOLIA_ADMIN_API_KEY=292************* ALGOLIA_INDEX_NAME=example ruby ./algolia_faraday_test.rb
Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!
/Users/paul/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/faraday-net_http-2.1.0/lib/faraday/adapter/net_http.rb:36: warning: already initialized constant Faraday::Adapter::NetHttp::NET_HTTP_EXCEPTIONS
/Users/paul/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/faraday-0.17.4/lib/faraday/adapter/net_http.rb:12: warning: previous definition of NET_HTTP_EXCEPTIONS was here
/Users/paul/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/algolia-2.3.0/lib/algolia/transport/transport.rb:79:in `request': Unreachable hosts (Algolia::AlgoliaUnreachableHostError)
        from /Users/paul/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/algolia-2.3.0/lib/algolia/transport/transport.rb:29:in `read'
        from /Users/paul/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/algolia-2.3.0/lib/algolia/search_index.rb:983:in `get_settings'
        from ./algolia_faraday_test.rb:19:in `<main>'

Looks like the version constraints in the gem still allow faraday <= 0.15 so we were able to install algolia 2.3.0.

Maybe the min faraday constraint needs locking down to a newer version?

paulspringett avatar Oct 07 '22 10:10 paulspringett

You're right, it seems like it needs at least version 1 of faraday in order to work as expected, as it relies on including faraday-net_http_persistent, which doesn't work well with version 0.x when including it. I tried to work around this in the faraday-v0-debug branch by only including the file if it's Faraday v1 or up, and it seems to work for me locally. Would it be possible for you to (temporarily) change your project's Gemfile to use the following as the constraint for Algolia gem, please?

gem 'algolia', git: '[email protected]:algolia/algoliasearch-client-ruby.git', branch: 'faraday-v0-debug'

If it works, I'll draft a new release for this today, which should fix your issue in v2.3.1 then 😄

DevinCodes avatar Oct 07 '22 11:10 DevinCodes

@DevinCodes Can confirm the faraday-v0-debug branch is working for us 👍

paulspringett avatar Oct 11 '22 13:10 paulspringett

@paulspringett this is available in v2.3.1 https://rubygems.org/gems/algolia/versions/2.3.1 !

DevinCodes avatar Oct 21 '22 13:10 DevinCodes

@DevinCodes Brilliant, thank you!

paulspringett avatar Oct 24 '22 15:10 paulspringett