2
votes

I'm trying to add Resque workers to a Heroku app. The app runs perfectly in my development environment, but when I deploy to Heroku and try to queue a job, I get the following:

Redis::InheritedError  Error
Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.

I've added RedisToGo to the app, and I've doubled-checked that the Redis URL is being given to Resque. That is, /config/initializers/redis.rb looks like this:

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS

Does anyone know what I might be doing wrong?

2

2 Answers

1
votes

@dB` There 2 way you can do this

a) Upgrade the Resque I guess it solve this issue since they are internally doing a reconnect check this and this

Now the above problem is because your job is basically a child process and child process inherit all open connection from the parent over here (redis connection as well) now moment your job completes it close the all open connection even redis connection which is shared by your worker hence the above error

Which result in give second solution If you dont have upgrade resque in mind perhaps the below solution would work

b) Trying to create a new connection/reconnect the existing redis connection in resque hooks after/before fork which ever of above suit you would help I believe

This way the redis connection would not go away even when child process exist

Hope this help

0
votes

When I asked this question, I was trying to run my Resque workers on a separate Heroku dyno. In the end, I gave up on this approach, and tried running them in the same dyno as my webserver, using Unicorn. I followed the setup instructions here and everything worked fine.