diff options
author | Matthew Draper <matthew@trebex.net> | 2016-07-06 08:28:06 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-07-06 08:28:06 +0930 |
commit | 76ce08a493fbd9f8c38d719f4c329bc2153204fc (patch) | |
tree | 1e04e58828bba3247eba15523efa6aab54fa0dbf /activerecord/lib/active_record | |
parent | 08a907461341486e371774dd69c43852657c0f4f (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 12 |
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 |