rails/rails — pull request #7684 by jrochkind (2012-09-18 16:38:06+00:00)
Title: ConnectionPool accepts spec key 'checkout_timeout' (Backport)

Backport of applicable parts of #6441 cb6f83935, in a backwards compatible way.

Previously, ConnectionPool uses connection spec key 'wait_timeout' (default 5 seconds) to decide how long a thread can block waiting for a connection to be avail before raising.

However, mysql2 adapter uses this same 'wait_timeout' key for an entirely different value -- setting the MySQL server's own 'wait timeout', how long the server will allow a connection to be idle before closing it. Default is several hours.

Extreme differences in default shows you often do not want these two values to be the same. But if you don't want them to be default, there is no supported API to change one without changing the other to be the same, since they both use 'wait_timeout'.

So this change maeks ConnectionPool use 'checkout_timeout' in the spec, prefering it over 'wait_timeout'. But 'wait_timeout' IS (unlike in master) still used if there without 'checkout_timeout'. If you want mysql2's 'wait_timeout' to be differnet than ConnectionPool's timeout, you can (and have to) set them both -- mysql2 will use the 'wait_timeout', ConnectionPool will use the 'checkout_timeout'. But prior to this patch there was _no_ way to do that.

The actual code change is very straightforward. But I wasn't sure how to write the test. The test is a bit wonky, if someone has a suggestion of how to organize the test better, please do share. @rafaelfranca , any interest/feedback?