diff options
author | Matthew Draper <matthew@trebex.net> | 2015-05-16 02:12:36 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-05-16 02:12:36 +0930 |
commit | 97c482ff8eb652d4c18ab49fba034c506be902b8 (patch) | |
tree | 71a6a10049f4b228916120cea30ce6ddcf5eb95f /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
parent | a4dd94c61fd00d0f64189f6889a741b185edba8b (diff) | |
parent | 603fe20c0b8c05bc1cca8d01caadbd7060518141 (diff) | |
download | rails-97c482ff8eb652d4c18ab49fba034c506be902b8.tar.gz rails-97c482ff8eb652d4c18ab49fba034c506be902b8.tar.bz2 rails-97c482ff8eb652d4c18ab49fba034c506be902b8.zip |
Merge pull request #14938 from thedarkone/pool-lock-fix
Reducing AR::ConPool's critical (synchronized) section
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 0705c22a8c..60655b673c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -7,7 +7,6 @@ require 'active_record/connection_adapters/schema_cache' require 'active_record/connection_adapters/sql_type_metadata' require 'active_record/connection_adapters/abstract/schema_dumper' require 'active_record/connection_adapters/abstract/schema_creation' -require 'monitor' require 'arel/collectors/bind' require 'arel/collectors/sql_string' @@ -70,7 +69,6 @@ module ActiveRecord include DatabaseLimits include QueryCache include ActiveSupport::Callbacks - include MonitorMixin include ColumnDumper SIMPLE_INT = /\A\d+\z/ @@ -141,12 +139,20 @@ module ActiveRecord SchemaCreation.new self end + # this method must only be called while holding connection pool's mutex def lease - synchronize do - unless in_use? - @owner = Thread.current + if in_use? + msg = 'Cannot lease connection, ' + if @owner == Thread.current + msg << 'it is already leased by the current thread.' + else + msg << "it is already in use by a different thread: #{@owner}. " << + "Current thread: #{Thread.current}." end + raise ActiveRecordError, msg end + + @owner = Thread.current end def schema_cache=(cache) @@ -154,6 +160,7 @@ module ActiveRecord @schema_cache = cache end + # this method must only be called while holding connection pool's mutex def expire @owner = nil end |