brianmario/mysql2 — pull request #287 by johnl (2012-08-06 20:01:55+00:00)
Title: Use mysql's own read timeout option too 

do_query implements its own read timeout using rb_wait_for_single_fd,
but blocking operations, like mysql_ping, will still block until the
tcp connection expires if there is a problem (multiple minutes
usually).

ActiveRecord's connection pool makes liberal use of ping, so an
unresponsive mysql server can cause rails apps to hang even if
read_timeout has been configured.

We fix this by using the mysql library's own MYSQL_OPT_READ_TIMEOUT
option. It fixes mysql_ping and seems not to interfere with with
do_query.

I don't think writing a test case for this is practical - it requires
dropping packets to/from the mysql server after establishing the
connection. I've tested it like this manually though and it makes all
your fast fail dreams come true.