How do I reset a Datamapper connection after Passenger opens a workflow?

After updating several parts of my Rails application (Ruby 1.9.2, Rails 3.0.4, Datamapper 1.1.0) and switching to offline mode, we began to receive strange MySQL connection errors, including:

  • Field Count Mismatch
  • Lost connection to MySQL server during query
  • MySQL server is gone

Then I remembered that Passenger processes are being processed, and you need to re-open new connections for things like redis, memcache, etc., or the data stream will be distorted, and I found another post to handle similar adventures from- for the same problem with MySQL.

But I also recalled that here, that the Passenger automatically took care of the connections to the database.

I have two questions:

1) How to inform DataMapper about creating and using a new database connection? And / or:

2) Does the passenger forking automatically or not? For fork sake ...;)

+4
source share
1 answer

To answer # 2, no, the Passenger himself does not process closing file descriptors after forking. You must manage it yourself, unless your stone does it for you.

To answer # 1, I put together some of the things I found. Add to environment.rb and let me know if it works!

if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| if forked # We're in smart spawning mode. DataObjects::Pooling.pools.each do |pool| pool.dispose end else # We're in direct spawning mode. We don't need to do anything. end end end 
+1
source

All Articles