Search code examples
ruby-on-railsherokuelasticsearchbonsai-elasticsearch

Rails app crashes on Heroku after implementing ElasticSearch


I just implemented ElasticSearch to my Rails App. Everything is working localy, but when I deployed my changes to Heroku, the app crashes.

When I run

heroku run rails c

in the Heroku cli, I get this error message:

/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection   refused - connect(2) (Faraday::ConnectionFailed)
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-  0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-  0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/base.rb:187:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/client.rb:102:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.4/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.4/lib/elasticsearch/api/actions/indices/create.rb:77:in `create'
from /app/app/models/publication.rb:67:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:307:in `depend_on'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:225:in `require_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:468:in `block (2 levels) in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:467:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:467:in `block in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:465:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:465:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:346:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `block in <module:Finisher>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
from /app/config/environment.rb:5:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in `require_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:8:in `require'
from /app/bin/rails:8:in `<main>'

On Heroku I installed the Bonsai ElasticSearch, but that didn't solve the problem.

I'm not that confident with ElasticSearch, did I forgot some configuration or something?

my repository is at:

https://github.com/acandael/posplus-rails

thanks for your help,

Anthony


Solution

  • The errors imply the app can't connect to Elasticsearch to create an index, so I would check if you can do that locally:

    $ heroku config | grep BONSAI_URL
    $ curl -XPUT '<your-bonsai-url>/myindex/'
    

    If this fails, then the problem is with the Elasticsearch cluster. If it succeeds, then you're probably not pointing the app at the correct URL.