Description
I'm looking into a potential issue with ActiveRecord4 and Sidekiq.
Since upgrading to AR4, my failure rate shot through the roof - from under 100 failures in 2 weeks to 1000 failures in the first hour after upgrading.
The error presented is this:
ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5.000 seconds (waited 5.001 seconds)
I have an ActiveRecord connection pool of 20. The first 20 jobs go through fine and I can see my connection pool growing, however when it hits 20, the errors start occurring.
It appears that either the connections aren't getting released or checked out appropriately.
If I replace the following line from the ActiveRecord Sidekiq middleware:
::ActiveRecord::Base.clear_active_connections! if defined?(::ActiveRecord)
...with a full disconnect:
::ActiveRecord::Base.clear_all_connections!
All works fine again - though obviously very inefficient.
I'm using a barebones ruby script for my worker that connects to ActiveRecord without rails:
::ActiveRecord::Base.establish_connection(
:adapter => configuration[:adapter],
:host => configuration[:host],
:username => configuration[:username],
:password => configuration[:password],
:database => configuration[:database],
:pool => configuration[:pool],
:port => configuration[:port],
:reaping_frequency => 10
)
self[:activerecord_cache] = ::ActiveSupport::Cache::MemoryStore.new
It's all very simple and the queue was running fine until now.
I'll plug away at this a bit more and if no luck, will get a skeleton repo up to reproduce it. Any input is appreciated.