Use mysql's own read timeout option too #287

Merged
merged 1 commit into from Aug 8, 2012

2 participants

@johnl

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.

@johnl johnl 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.
82aa624
@brianmario brianmario merged commit ee4b12d into brianmario:master Aug 8, 2012
@apepper apepper referenced this pull request in infopark/mysql_blob_streaming May 6, 2013
Merged

Updated to mysql2 version 0.3.12b6. #4

@apepper apepper added a commit to apepper/mysql_blob_streaming that referenced this pull request Apr 24, 2014
@apepper apepper Updated to mysql2 version 0.3.12b6.
This contains an important bugfix, so that timeouts of c mysql are correctly used. More details see brianmario/mysql2#287 .

This is an issue with AWS RDS, which once in a while delays queries up to 15 minutes. Details see https://forums.aws.amazon.com/thread.jspa?messageID=446622&tstart=0https://forums.aws.amazon.com/thread.jspa?threadID=122020&tstart=0 and https://forums.aws.amazon.com/thread.jspa?threadID=122035&tstart=0
a2a989a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment