aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorYoshioka Tsuneo <yoshiokatsuneo@gmail.com>2015-01-09 14:33:17 +0900
committerYoshioka Tsuneo <yoshiokatsuneo@gmail.com>2015-01-09 14:33:17 +0900
commit205a561e50c89f7b81336a295f97209d741cfa67 (patch)
treefb4708b57bf777d2dc99e1fa90e8b66114a3b5f3 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parenta74041d483041345454e766c506dab1b567dec0d (diff)
downloadrails-205a561e50c89f7b81336a295f97209d741cfa67.tar.gz
rails-205a561e50c89f7b81336a295f97209d741cfa67.tar.bz2
rails-205a561e50c89f7b81336a295f97209d741cfa67.zip
ActiveRecord: release connection on reconnect failure.
When trying to checkout connection from connection pool, checkout()(and checkout_and_verify) verify whether the connection is active or not. And, if the connection is not active, connection adapters try to reconnect to server. And, if database is down at this moment, reconnect fails and exception is raised. (Ex: Mysql2::Error: Can't connect to local MySQL server through socket xxx) But, ConnectionPool does not catch the exception, but leaks current disconnected connection to @connection. So, if database's temporary down happens several times and exceeds the number of connection pool(5 by default), activerecord will be no more available, even if database server is already recovered. This patch fix it by catching exception and releasing connection.
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.rb3
1 files changed, 3 insertions, 0 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 1371317e3c..6b5081b7a9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -453,6 +453,9 @@ module ActiveRecord
c.verify!
end
c
+ rescue
+ disconnect!
+ raise
end
end