Rails Resque Workers Fail with Pgerror: Server Closed the Connection Unexpectedly

Rails Resque workers fail with PGError: server closed the connection unexpectedly

When I created Nestor, I had the same kind of problem. The solution was to re-establish the connection in the forked process. See the relevant code at http://github.com/francois/nestor/blob/master/lib/nestor/mappers/rails/test/unit.rb#L162

From my very limited look at Resque code, I believe a call to #establish_connection should be done right about here: https://github.com/resque/resque/blob/master/lib/resque/worker.rb#L123

Resque worker failing with PostgreSQL server

Adding the following to my Rakefile fixed a similar problem for me:

task "resque:setup" => :environment do
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

This reconnects PostgreSQL before Resque forks its process to create a worker.

Resque.enqueue failing on second run

This has solved it for me:

require 'resque/tasks'

task "resque:setup" => :environment do
ENV['QUEUE'] = '*'

Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

Source: carhartl comment on Github

pg Ruby gem is throwing a prepared statement already exists error from Resque

I found the answer. Please look at Christian Fazzini's answer here:

Rails Resque workers fail with PGError: server closed the connection unexpectedly

The error is different, but Christian's solution is the same, and it works.

Resque/Rails/Heroku: PG::Error: result has been cleared

This error message indicates an internal error in the PG gem that is being used to interface with the Postgres database. It indicates a Garbage Collection/memory allocation error where the result of the executed postgres query has been cleared from memory on access.

Someone as heroku will have to debug this, it appears to be a platform level issue.

setup resque with mongoid

It looks like disconnect does actually kills off the mongoid connection, I was getting confused because I was expecting an similar error I got when I tried out with active record but looks like mongoid autoconnects when needed.

I verified that the connection was killed using mongo console, you can do a db.serverStatus().connections to view the number of connections and see that disconnect will decrease the current connections.



Related Topics



Leave a reply



Submit