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
In Rails - Is There a Rails Method to Convert Newlines to <Br>
Problems with the Rails Console, Rvm and Readline
Rails 3.1 Pipeline - Exclude JavaScript File
Rails with Ruby-Debugger Throw 'Symbol Not Found: _Ruby_Current_Thread (Loaderror)'
How to Encode Media in Base64 Given Url in Ruby
Best Way to Debug Third-Party Gems in Ruby
Warning: Constant ::Fixnum Is Deprecated When Generating New Model
How to Set Default Ruby Version with Rvm
How to Generate a Human Readable Time Range Using Ruby on Rails
Ruby Read CSV File as Utf-8 And/Or Convert Ascii-8Bit Encoding to Utf-8
Best Way to Highlight Current Page in Rails 3? - Apply a CSS Class to Links Conditionally
Finding Out Current Index in Each Loop (Ruby)
How to Find the Unique Elements in an Array in Ruby
What Is an Illegal Octal Digit