This ActiveRecord::ConnectionTimeoutError can, in my opinion, occur only in one scenario - when there are so many threads that want to use database connections that the pool is exhausted and even waits for a free connection, it does not help (as described in the source code ).
In your case, this is strange. You use only 25 worker threads, but 100 connections are established in the pool, so there are many reserves. I still suspect you should have threads. Perhaps you make some threads in your workplaces? Perhaps you are using a gem that creates streams in your work?
In any case, if you can throw an exception, I would suggest catching it and getting a list of all the threads at the time it occurred, something like this:
begin # job stuff... rescue ActiveRecord::ConnectionTimeoutError puts "listing #{Thread.list.count} threads:" Thread.list.each_with_index do |t,i| puts "---- thread #{i}: #{t.inspect}" puts t.backtrace.take(5) end end
I expect there will be 100 or more threads, and you should see exactly where they got stuck from the backtrace.
source share