Last active
January 15, 2016 15:21
-
-
Save jrafanie/f15970a7cb1d232bcd42 to your computer and use it in GitHub Desktop.
Testing if Process.fork requires 4.2 ActiveRecord disconnect/reconnect before after fork
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" | |
| SchemaMigration.count | |
| # Place I thought we'd need to disconnect | |
| # ActiveRecord::Base.clear_all_connections! | |
| puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" | |
| 10.times do | |
| pid = fork do | |
| puts "Child: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" | |
| # Place I thought children may need to reconnect | |
| # ActiveRecord::Base.establish_connection | |
| SchemaMigration.count | |
| puts "Child: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" | |
| sleep 2 | |
| exit! | |
| end | |
| Process.detach(pid) | |
| end | |
| sleep 5 | |
| puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" | |
| SchemaMigration.count | |
| puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment