diff options
author | Kevin Casey <kacasey@berkeley.edu> | 2014-02-08 17:38:54 -0800 |
---|---|---|
committer | Kevin Casey <kacasey@berkeley.edu> | 2014-02-08 17:38:54 -0800 |
commit | 02a3c0e771b3e09173412f93d8699d4825a366d6 (patch) | |
tree | e89319efc7f7d01091f307aaebb1b79f5910f38c /activerecord/lib/active_record/connection_adapters | |
parent | 1ec25d15d9c2e19df0195165b99335a006d449b6 (diff) | |
download | rails-02a3c0e771b3e09173412f93d8699d4825a366d6.tar.gz rails-02a3c0e771b3e09173412f93d8699d4825a366d6.tar.bz2 rails-02a3c0e771b3e09173412f93d8699d4825a366d6.zip |
Reaper has access to threadsafe active? call
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
3 files changed, 13 insertions, 2 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 cebe741daa..759e162e19 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -393,7 +393,7 @@ module ActiveRecord synchronize do stale = Time.now - @dead_connection_timeout connections.dup.each do |conn| - if conn.in_use? && stale > conn.last_use && !conn.active? + if conn.in_use? && stale > conn.last_use && !conn.active_threadsafe? remove conn end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 3c94bad208..11b28a4858 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -262,6 +262,12 @@ module ActiveRecord def active? end + # Adapter should redefine this if it needs a threadsafe way to approximate + # if the connection is active + def active_threadsafe? + active? + end + # Disconnects from the database if already connected, and establishes a # new connection with the database. Implementors should call super if they # override the default implementation. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 9618ba4087..36c7462419 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -586,11 +586,16 @@ module ActiveRecord # Is this connection alive and ready for queries? def active? - @connection.connect_poll != PG::PGRES_POLLING_FAILED + @connection.query 'SELECT 1' + true rescue PGError false end + def active_threadsafe? + @connection.connect_poll != PG::PGRES_POLLING_FAILED + end + # Close then reopen the connection. def reconnect! super |