【发布时间】:2018-01-15 07:44:55
【问题描述】:
我得到了
RuntimeError: The connection cannot be reused in the forked process
来自
ruby-oci8 (2.1.3) lib/oci8/cursor.rb:28:in `__initialize'
我正在将 oracle db 用于 rails 应用程序,最近我开始使用 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
【问题讨论】:
-
这似乎与您的 gem 无关,而与您的服务器堆栈有关。你可能会从这篇文章中得到一些有用的信息Deploying Rails Applications with Unicorn
-
在
unicorn.rb中添加了相同的配置,但仍然出现相同的错误。 -
对于一个架构我没有收到任何错误,对于一个具有相同用户名和密码的特定架构,我收到了错误。
标签: ruby-on-rails ruby nginx unicorn