RuntimeError: The connection cannot be reused in the forked process (ruby-oci8 gem)
RuntimeError: The connection cannot be reused in the forked process (ruby-oci8 gem)
我得到
RuntimeError: The connection cannot be reused in the forked process
来自
ruby-oci8 (2.1.3) lib/oci8/cursor.rb:28:in `__initialize'
我正在为 rails 应用程序使用 oracle 数据库,最近我开始使用 unicorn
和 nginx
部署 rails 应用程序,从他们开始我收到这个错误帮助。
我正在使用 ruby 1.9.3
和 rails 3.1
,这是我的 unicorn.rb
文件
rails_env = ENV['RAILS_ENV'] || 'production'
worker_processes 6
preload_app true
timeout 75
app_dir = File.expand_path("../../..", __FILE__)
shared_path = "#{app_dir}/shared"
working_directory "#{app_dir}/current"
# Set up socket location
listen "#{shared_path}/sockets/unicorn.sock", :backlog => 64
# Set master PID location
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.log"
stdout_path "#{shared_path}/log/unicorn.log"
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# reset the connection since the pre-forked connection will be stale
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(ActiveRecord::Base)
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
end
end
我得到了解决方案。基本上我的模型包含这样的 establish_connection
定义
class User < ActiveRecord::Base
establish_connection "user_#{Rails.env}"
end
我的 unicorn.rb
文件 before_fork
块包含以下代码。
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
我发现当您在模型中显式编写 establish_connection
时,上面的代码不起作用。为了解决这个问题,我不得不将上面的代码更改为下面的代码
defined?(ActiveRecord::Base) &&
ActiveRecord::Base.remove_connection(User) &&
ActiveRecord::Base.connection.disconnect!
它就像一个魅力。 :-)
我得到
RuntimeError: The connection cannot be reused in the forked process
来自
ruby-oci8 (2.1.3) lib/oci8/cursor.rb:28:in `__initialize'
我正在为 rails 应用程序使用 oracle 数据库,最近我开始使用 unicorn
和 nginx
部署 rails 应用程序,从他们开始我收到这个错误帮助。
我正在使用 ruby 1.9.3
和 rails 3.1
,这是我的 unicorn.rb
文件
rails_env = ENV['RAILS_ENV'] || 'production'
worker_processes 6
preload_app true
timeout 75
app_dir = File.expand_path("../../..", __FILE__)
shared_path = "#{app_dir}/shared"
working_directory "#{app_dir}/current"
# Set up socket location
listen "#{shared_path}/sockets/unicorn.sock", :backlog => 64
# Set master PID location
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.log"
stdout_path "#{shared_path}/log/unicorn.log"
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# reset the connection since the pre-forked connection will be stale
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(ActiveRecord::Base)
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
end
end
我得到了解决方案。基本上我的模型包含这样的 establish_connection
定义
class User < ActiveRecord::Base
establish_connection "user_#{Rails.env}"
end
我的 unicorn.rb
文件 before_fork
块包含以下代码。
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
我发现当您在模型中显式编写 establish_connection
时,上面的代码不起作用。为了解决这个问题,我不得不将上面的代码更改为下面的代码
defined?(ActiveRecord::Base) &&
ActiveRecord::Base.remove_connection(User) &&
ActiveRecord::Base.connection.disconnect!
它就像一个魅力。 :-)