kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

RuntimeError: The connection cannot be reused in the forked process. #184

Closed brahamshakti closed 6 years ago

brahamshakti commented 6 years ago

Hi I am using ruby-1.9.3, rails 3.1 and ruby-oci8 2.1.3. I am using unicorn with nginx for deployment.

I am getting

RuntimeError: The connection cannot be reused in the forked process.
ruby-oci8 (2.2.5.1) lib/oci8/cursor.rb:28:in `__initialize'

This is my unicorn.rb file

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

I am using multiple schema in rails application. For one schema it is loading the application and for one specific schema I am getting the error. What should I do now to resolve this error. Thanks

kubo commented 6 years ago

I closed the issue because @brahamshakti seems to resolve it.

brahamshakti commented 6 years ago

I tried that approach and it worked but just to ensure, did the approach I used is correct or not?

kubo commented 6 years ago

Sorry, I know little about rails. I use ruby without rails.