aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-07-06 08:28:06 +0930
committerMatthew Draper <matthew@trebex.net>2016-07-06 08:28:06 +0930
commit76ce08a493fbd9f8c38d719f4c329bc2153204fc (patch)
tree1e04e58828bba3247eba15523efa6aab54fa0dbf /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
parent08a907461341486e371774dd69c43852657c0f4f (diff)
downloadrails-76ce08a493fbd9f8c38d719f4c329bc2153204fc.tar.gz
rails-76ce08a493fbd9f8c38d719f4c329bc2153204fc.tar.bz2
rails-76ce08a493fbd9f8c38d719f4c329bc2153204fc.zip
Check connection ownership before allowing a thread to release it
A thread can only release a connection if it owns it, or it's owned by a thread that has died.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index d4b9e301bc..5140238571 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -184,7 +184,17 @@ module ActiveRecord
# this method must only be called while holding connection pool's mutex
def expire
- @owner = nil
+ if in_use?
+ if @owner != Thread.current && @owner.alive?
+ raise ActiveRecordError, "Cannot expire connection, " <<
+ "it is owned by a different thread: #{@owner}. " <<
+ "Current thread: #{Thread.current}."
+ end
+
+ @owner = nil
+ else
+ raise ActiveRecordError, 'Cannot expire connection, it is not currently leased.'
+ end
end
def unprepared_statement