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?
source share