提交 205a561e 编写于 作者: Y Yoshioka Tsuneo

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.
上级 a74041d4
......@@ -453,6 +453,9 @@ def checkout_and_verify(c)
c.verify!
end
c
rescue
disconnect!
raise
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册