From 205a561e50c89f7b81336a295f97209d741cfa67 Mon Sep 17 00:00:00 2001 From: Yoshioka Tsuneo Date: Fri, 9 Jan 2015 14:33:17 +0900 Subject: 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. --- .../lib/active_record/connection_adapters/abstract/connection_pool.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3