On Feb 22, 2013, at 9:54 AM, Jeremy Evans <[email protected]> wrote:
> 
> FWIW, spawn is fork then exec in unix, not that it matters since I'm guessing 
> passenger actually does call fork.  Try disconnecting before forking/spawning.

Jeremy's absolutely correct: database connections which are opened before 
forking/spawning absolutely need to be reset afterwards. I am the maintainer of 
the 'pg' gem, and I answer about 2 questions like this per week, always with 
the same advice.

Here's how I do it in a little distributed-jobs framework that uses 
PostgreSQL+Sequel for queuing:


  # Called by every child on startup.
  def after_fork
    reset_file_descriptors
    #...
  end
  
  # Reconnect so we aren't using the parent's connection
  def reset_file_descriptors
    DB.synchronize do |conn|
      conn.reset
    end
  end



--
Michael Granger <[email protected]>
Rubymage, Architect, Believer
The FaerieMUD Consortium <http://faeriemud.org/>




-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to