Ruby fragmentation reinforced compound after sleep

Thank you for attention. We are a bit stuck with tied connections after some period of inactivity and we will be grateful for any help or to try something.

We are using v1.4.1 from activerecord-oracle_enhanced-adapter with ojdbc6.jar in the Sinatra app on jruby 1.7.2. My controller calls the helper class method and returns a json string. The helper class method simply queries the Oracle database for the data. The code is as follows:

class App < Sinatra::Base  get '/customer/:id_number' do |id_number|   MyHelper.customer(id_number).to_json  end end class MyHelper  @dbconfig = YAML.load_file("../config/database.yml")  @dbenv = @dbconfig["#{settings.environment}"]  puts "establish_connection"  ActiveRecord::Base.establish_connection(@dbenv)  def self.customer(id_number)   begin    query = <<-SQL SELECT * FROM customer WHERE cust_id = '#{id_number}' SQL    puts 1    ActiveRecord::Base.connection.exec_query(query)    puts 2   rescue => e    puts 3    puts e.message   ensure    puts 4 ActiveRecord::Base.clear_active_connections!    puts 5   end   end end 

We have a shell script that gets into the controller 50 times, sleeps for 2 hours and repeats. We can see one call to establish a connection at the beginning (expected). We do not expect that immediately after sleep, the first database connection always gets stuck. What we will see in the magazine is just "1". After 15 minutes, the client disconnects and makes another call to the controller. This second call seems to affect the wake up of the connection pool, as it always resumes thread 1, and so we will see “2”, “4” and “5”. At the same time, we also see thread log messages 2: "1", "2", "4" and "5". We know, because the actual code prints Thread.current.object_id as part of the message.

We tried adding ActiveRecord :: Base.connection.verify! right before exec_query, but this only shifts the stuck call to the check string.

Did we use the adapter correctly? Is there anything else we can try?

+4
source share
1 answer

I implemented the solution using the event machine and the oracle adapter, yes, the error was there, the only way to "fix" this problem made my application reconnect to oracle, so here is my example

 unless ActiveRecord::Base.connection.active? begin ActiveRecord::Base.connection.reconnect! rescue => e EchoServer.log e end end 

So, before each Active Record connection, I ask if the connection is alive, if not, I try to restore the connection manually, while it works, but this is not the best solution, but .... I hope it will work

PD: there are some problems associated with this error, here are a few of them:

https://github.com/rsim/oracle-enhanced/issues/420

Does reaper work with an oracle extension adapter (OCI) to get unused connections?

0
source

All Articles