aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorBrent Wheeldon <brent.wheeldon@gmail.com>2018-01-12 15:58:04 -0500
committerBrent Wheeldon <brent.wheeldon@gmail.com>2018-03-23 15:53:19 -0400
commit0a1ed447999d0092e8d0e86729666fc3b4577151 (patch)
treecf67e13a66869acc5cb10bf8357da272340c3f74 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent6aa5cf03ea8232180ffbbae4c130b051f813c670 (diff)
downloadrails-0a1ed447999d0092e8d0e86729666fc3b4577151.tar.gz
rails-0a1ed447999d0092e8d0e86729666fc3b4577151.tar.bz2
rails-0a1ed447999d0092e8d0e86729666fc3b4577151.zip
Prevent deadlocks when waiting for connection from pool.
When a thread that had the load interlock but was blocked waiting to check a connection out of the connection pool but all of the threads using the available connections were blocked waiting to obtain the load interlock an `ActiveRecord::ConnectionTimeoutError` exception was be thrown by the thread waiting for the connection. When waiting for the connection to check out we should allow loading to proceed to avoid this deadlock.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index c730584902..be999e7749 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -188,7 +188,9 @@ module ActiveRecord
t0 = Time.now
elapsed = 0
loop do
- @cond.wait(timeout - elapsed)
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
+ @cond.wait(timeout - elapsed)
+ end
return remove if any?