Redis tries to connect to localhost on Heroku instead of REDIS_URL

12,041

Solution 1

I can think of two possibilities:

  • Is something setting ENV['REDIS_URL'] before the initializer runs? For instance maybe you have a .env file checked into git that is overriding the Heroku variable?

  • You say this code is from redis.rb. Do you have a config/initializers/resque.rb also? What about config/resque.yml? Either of those may be also trying to open a Redis connection. (If you could post the entire stack trace of your error, you could confirm this or rule it out.) Or are you using Redis for anything other than Resque?

You could also do some printf debugging and change your initializer to say:

if Rails.env.production?
  puts "production: #{ENV['REDIS_URL']}"
  uri = URI.parse(ENV["REDIS_URL"])
else
  puts "not production"
  uri = URI.parse("redis://localhost:6379")
end

That should help you clarify what's going on. (You may need to use Rails.logger.info instead of puts.)

EDIT: That stack trace is very helpful! Sure enough, your own initializer isn't in there at all, but there is other code trying to load its own redis connection, here:

remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-web-0.0.9/config/initializers/resque_config.rb:4:in `<top (required)>'

If you look up that gem, you can see it is doing this:

require 'resque'

config = ENV.fetch("RAILS_RESQUE_REDIS", "127.0.0.1:6379")
Resque.redis = config

So I think the answer is to set RAILS_RESQUE_REDIS in addition to REDIS_URL. You can use the Heroku config:set command to do that.

Solution 2

You forgot to pass the USERNAME to the connector, and your REDIS_URL can have been changed by the service provider...

I recommend use

$redis = if Rails.env.production? ? Redis.new(ENV["REDIS_URL"]) : Redis.new("redis://localhost:6379")

It would be even better use the env variable your service provider set, like ENV['REDISCLOUD_URL'], because if they change the url for any motive, like when you update a plan or they need to change their infra... they could just set their variable and it would be transparent for you, without any interruption of service.

If you maintain yourself the REDIS_URL, and they change their url, your app will lost access to until you figure out the URL should change and set the update the REDIS_URL again

OBS

If the problem is when setting up the worker... the problem can be even that it is not starting with the correct environment, at least if you run it on Rails 5, you should config your resque Rakefile to

#If you're using Rails 5.x, include the following in lib/tasks/resque.rb:

require 'resque/tasks'
task 'resque:setup' => :environment

Solution 3

Inside of your config/initializes/set_redis_url.rb

ENV['REDIS_URL'] = ENV["REDISCLOUD_URL"] if ENV["REDISCLOUD_URL"]

In my past i have used action cable to work with redis and my app wouldn't work without these lines in config/environments/production.rb

config.action_cable.allowed_request_origins = ['https://your-app.herokuapp.com',
                                           'http://your-app.herokuapp.com']

config.action_cable.url = "wss://sitepoint-custom-messaging.herokuapp.com/cable"
Share:
12,041

Related videos on Youtube

John
Author by

John

I am a Ruby developer working on several projects for several customers. Currently I spend a lot of time on the amazing Meteor framework. I am developing Yapma both as a learning experience and as my personal project management app. Beside my development activities, I also work as a test automation &amp; performance engineer. I am very experienced in using a wide range of test tools and I am a huge advocate of using open-source test tooling like JMeter and Selenium. I am certified for ISEB, Prince 2, HP Certified Product Consultant (CPC) LoadRunner and Certified Scrum Master.

Updated on July 03, 2022

Comments

  • John
    John almost 2 years

    I have a Rails app which uses Redis for background jobs. On Heroku I use the Heroku Redis add-on. When I deploy to Heroku, it gives me this error:

    Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379
    

    It seems it tries to connect to localhost. I have both a REDIS_URL and REDIS_PROVIDER environment variable on Heroku. And this is how my redis.rb looks like:

    if Rails.env.production?
      uri = URI.parse(ENV["REDIS_URL"])
    else
      uri = URI.parse("redis://localhost:6379")
    end
    Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    

    And this is my Procfile:

    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
    worker: env TERM_CHILD=1 bundle exec rake environment resque:work QUEUE=* COUNT=1
    

    Any ideas why it is not working? Even if I change redis.rb so it only has the REDIS_URL as url, it gives the same error.

    Update: added error trace:

    remote:        Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:345:in `rescue in establish_connection'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:331:in `establish_connection'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:101:in `block in connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:293:in `with_reconnect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:100:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:364:in `ensure_connected'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:221:in `block in process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:306:in `logging'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:220:in `process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:120:in `call'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:351:in `block in time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `block in synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:350:in `time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:435:in `call_with_namespace'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:321:in `method_missing'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:100:in `redis_time_available?'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:15:in `initialize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `new'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `redis='
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-web-0.0.9/config/initializers/resque_config.rb:4:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/notifications.rb:166:in `instrument'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:647:in `load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `run'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `tsort_each_child'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:352:in `initialize!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/config/environment.rb:5:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:328:in `require_environment!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
    remote:        Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:6379
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:206:in `rescue in connect_addrinfo'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:198:in `connect_addrinfo'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:239:in `block in connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `each_with_index'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:313:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:336:in `establish_connection'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:101:in `block in connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:293:in `with_reconnect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:100:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:364:in `ensure_connected'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:221:in `block in process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:306:in `logging'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:220:in `process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:120:in `call'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:351:in `block in time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `block in synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:350:in `time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:435:in `call_with_namespace'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:321:in `method_missing'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:100:in `redis_time_available?'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:15:in `initialize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `new'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `redis='
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-web-0.0.9/config/initializers/resque_config.rb:4:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/notifications.rb:166:in `instrument'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:647:in `load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `run'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `tsort_each_child'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:352:in `initialize!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/config/environment.rb:5:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:328:in `require_environment!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
    remote:        IO::EINPROGRESSWaitWritable: Operation now in progress - connect(2) would block
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:199:in `connect_addrinfo'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:239:in `block in connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `each_with_index'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:237:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/connection/ruby.rb:313:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:336:in `establish_connection'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:101:in `block in connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:293:in `with_reconnect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:100:in `connect'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:364:in `ensure_connected'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:221:in `block in process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:306:in `logging'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:220:in `process'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis/client.rb:120:in `call'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:351:in `block in time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `block in synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:58:in `synchronize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib/redis.rb:350:in `time'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:435:in `call_with_namespace'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/redis-namespace-1.5.3/lib/redis/namespace.rb:321:in `method_missing'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:100:in `redis_time_available?'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque/data_store.rb:15:in `initialize'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `new'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-1.27.2/lib/resque.rb:125:in `redis='
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/resque-web-0.0.9/config/initializers/resque_config.rb:4:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/notifications.rb:166:in `instrument'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:647:in `load_config_initializer'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in `run'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `each'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in `tsort_each_child'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:352:in `initialize!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/config/environment.rb:5:in `<top (required)>'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:328:in `require_environment!'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/railties-5.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
    remote:        /tmp/build_329306a238b046dda86a54d29db48f4c/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
    remote:        Tasks: TOP => environment
    remote:        (See full trace by running task with --trace)
    remote:  !
    remote:  !     Precompiling assets failed.
    remote:  !     Attempted to access a nonexistent database:
    remote:  !     https://devcenter.heroku.com/articles/pre-provision-database
    remote:  !
    remote:  !     Push rejected, failed to compile Ruby app.
    remote: 
    remote:  !     Push failed
    remote: Verifying deploy....
    remote: 
    remote: !   Push rejected to backbone-app-staging.
    remote: 
    To [email protected]:backbone-app-staging.git
     ! [remote rejected] rails5 -> master (pre-receive hook declined)
    error: failed to push some refs to '[email protected]:backbone-app-staging.git'
    
    • 31piy
      31piy about 7 years
      What RAILS_ENV is set to when you run heroku config?
    • John
      John about 7 years
      That one was missing, but after adding that environment variable, it still returns the same error unfortunately. Silly thing is that I have another Rails app on Heroku with the exact same setup which is working...
    • Slava.K
      Slava.K about 7 years
      @John do you really need to parse url? According to docs redis can receive url parameter as config option: Redis.new(url: ENV["REDIS_URL"])
    • John
      John about 7 years
      @Slava.K you mean replacing the entire redis.rb with Redis.new(url: ENV["REDIS_URL"])?
    • Slava.K
      Slava.K about 7 years
      @John yes, can you try it?
    • 31piy
      31piy about 7 years
      I think it is always picking up the URL "redis://localhost:6379" due to Rails.env.production? is false. There is no way heroku can automatically generate URL like the one you specified. Please check what the environment is set to by running heroku run rails c, and then Rails.env in the console.
    • John
      John about 7 years
      @31piy Rails.env returns production
    • Shairon Toledo
      Shairon Toledo about 7 years
      What's the output for heroku config:get REDIS_URL ?
    • Robert Moskal
      Robert Moskal about 7 years
      I'm curious to know what happens if you take the evaluation out of the picture. Don't check Rails.env.production. Always connect to ENV["REDIS_URL"]
    • John
      John about 7 years
      @ShaironToledo: it is redis://h:[email protected]‌​:16369 (xxx and 999 not the real values of course)
    • Keval Gohil
      Keval Gohil about 7 years
      Then check your resque config ... Resque.redis = 'localhost:6379'
    • Thomas Lehoux
      Thomas Lehoux about 7 years
      Possible duplicate of this ? stackoverflow.com/questions/23247982/…
    • 31piy
      31piy about 7 years
      Can you try migrating the same settings to a fresh new heroku app?
    • John
      John about 7 years
      @31piy I have another Rails app on Heroku with the exact same settings and there is works fine.
  • John
    John about 7 years
    I'm using Heroku Redis and their env variable is ENV["REDIS_URL"], so that should be OK. I made the changes, but still returns the same error.
  • cefigueiredo
    cefigueiredo about 7 years
    Can you paste the trace produced by that error? And are you sure this script are being run? If you place a Rails.logger.info "TRY TO CONFIG THINGS" at the beginning of this script that text appears on the log?
  • John
    John about 7 years
    Hi, thanks for your suggestions, I have added the error trace. There is no config/initializers/resque.rb and also no config/resque.yml, just a config/initializers/redis.rb.
  • Ahmad Saleem
    Ahmad Saleem about 7 years
    You, sir, are a lifesaver! I was having the exact same issue, and setting RAILS_RESQUE_REDIS fixed it for me, but someone needs to file this issue with heroku. It seems to be a pretty recent bug.