Skip to content

Instantly share code, notes, and snippets.

@jrafanie
Last active January 15, 2016 15:21
Show Gist options
  • Save jrafanie/f15970a7cb1d232bcd42 to your computer and use it in GitHub Desktop.
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
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