From: Daniel DeLorme Date: 2009-06-23T08:48:47+09:00 Subject: Re: ActiveRecord.connection_pool separate connections for each p Virendra Negi wrote: > Hi! > > I am creating an ActiveRecord connection. In my code I am forking > multiple processes which uses this ActiveRecord connection. > However when the forked process ends it release the ActiveRecord > Connection and I get the exception Mysql::Error: MySQL server has gone > away I also wrestled with this problem for a long time. The problem is that when the mysql connection is finalized, either because the process exits or due to garbage collection, it sends a "close" message to the server. The parent process, which uses the same connection, suddenly finds the server is no longer there. Here is the solution that I found: Process.fork{ ActiveRecord::Base.active_connections.values.each(&:connect) #do your stuff here } This code establishes a new connection for each forked child, but without shutting down the connection inherited from the parent. Daniel