From: Virendra Negi Date: 2009-06-22T21:14:02+09:00 Subject: ActiveRecord.connection_pool separate connections for each p 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 can catch the exception and establish the ActiveRecord connection again, but this would involve a number or rescue statements and it would be cumbersome. Is it possible that I can use a connection from the connection pool and then, each forked process uses the separate connection within the process and return it back to the pool once i am through with it? Thanks Glen Code : - fold - unfold 1. require "rubygems" 2. require "active_record" 3. 4. ActiveRecord::Base.establish_connection( 5. :adapter => "mysql", 6. :username => "root", 7. :database => "test_dev", 8. :pool => 5 # Setting the pool size to 5 9. ) 10. 11. class TestDb < ActiveRecord::Base 12. set_table_name "test_dbs" 13. end 14. 15. 16. puts "Parent Process - the first record of the db is #{TestDb.first.id}" 17. 18. Process.fork do 19. puts "In the forked process the first record id is #{TestDb.first.id}" 20. # The forked process releases the connection here. 21. end 22. 23. sleep(2) # This is just to simulate exit of the process first and releasing the connection. 24. 25. # No ActiveRecord connection as it has been released by the forked process. 26. puts "Parent Process the first record id is #{Testdb.first.id}" thank anyway -- Posted via http://www.ruby-forum.com/.